如何将智能标记添加到我的.NET组件?

Wae*_*oul 6 .net c# vb.net components visual-studio

请看下面的图片,它显示了DataGridView的智能标记.

DataGridView智能标签http://img199.imageshack.us/img199/5871/post517531249536112.jpg

现在我正在创建一个新组件,我希望它支持在智能标记中显示一些属性.如何将属性添加到智能标记?

Joh*_*ers 5

我使用了http://msdn.microsoft.com/en-us/library/default.aspx?q=smart+tag+windows+forms+designer.

因此,我发现了演练:将智能标记添加到Windows窗体组件.

执行相同搜索的任何人都会找到相同的文章.


更新:该链接不再有效.我刚刚尝试搜索"智能标记窗体表单设计器",并发现"演练:将智能标记添加到Windows窗体组件"作为第一个搜索命中.Google中的相同搜索显示"如何:将智能标记附加到Windows窗体组件"作为第一个匹配,但显示与第二次匹配相同的演练.

  • @All:如果你认为我关心这个数字,那么我就给人留下了错误的印象.我想知道downvotes的原因,就是这样.我实际上认为,有时候,重要的是要植入你的脚,而不是向错误的方向推进.如果我们"让"开发人员来到这里并要求一些专家为他们做所有事情,那么他们将永远不会成为专家.这对他们不利,对我们不利,我还没准备好停止试图影响它. (9认同)
  • 是.从提问者的角度来考虑这个问题 - 花费30秒钟在数千名专家面前提出一个问题,而不是2分钟可能会或根本不会产生任何帮助.这就是我们的目标.粗鲁有损于其他有用的答案. (7认同)
  • 怎么没用?这是演练.有人应该在这里重复演练吗?并且,我认为假设OP能够进行搜索并且然后向他显示我使用的搜索词,我认为这不会是屈尊俯就.如果这是一些复杂的搜索我会认为他自己太愚蠢了,那就是居高临下. (4认同)
  • @John我不一定同意它是居高临下,但这很粗鲁.您的回答意味着在个人搜索失败后,SO应该是最后的手段.没有理由这样做.如果SO成为人们转向编程问题的第一个地方,那就太好了.我们只希望用户做出合理的努力,不发布重复的问题,没有别的. (3认同)
  • @Rex:这是一个虚假的经济,将导致一个分层的开发者社区.会有人知道,也会有人问.那不健康.请注意,顺便说一句,它没有花费专家花两分钟时间进行搜索!如果OP不知道MSDN搜索,我发布链接的事实教会了他.如果他无法弄清楚使用哪些搜索词(也许他没有尝试"设计师"),我向他展示了要使用的搜索词.我试图让他成为我的_equal_,而不是继续优于他! (3认同)
  • 所以你要说的是,关于SO的每个问题的答案都应该是"去Google,输入你的问题."?这不是这个网站的意思.此外,在我看来,在这个社区中说"我确定你有能力......"是非常粗鲁的,并且充满了屈尊俯就. (3认同)
  • 哦,来吧!是否表示他花了我两分钟的时间? (2认同)
  • @Pwninstein:你走开了.我认为这是一个非常好的问题,如果他花了两分钟,他就会得到他的直接答案,知道在MSDN中寻找相关答案的地方,并且本来可以回到这里要求澄清,以及实际_does_需要专家的信息. (2认同)

Bel*_*lom 3

您可以使用以下代码查看自定义控件中的示例标记。

\n\n

您可以从 www.windowsclient.com 获取有关该内容的视频。

\n\n
\n\n
using System;\nusing System.Collections.Generic;\nusing System.ComponentModel;\nusing System.Drawing;\nusing System.Data;\nusing System.Text;\nusing System.Windows.Forms;\nusing System.ComponentModel.Design;\nnamespace MakeSmartTag\n{\n    public enum Languages\n    {\n        English,\n        Arabic,\n        Japanese\n    }\n\n    [Designer(typeof(UserControlDesigner))]\n    public partial class UserControl2 : UserControl\n    {\n        public UserControl2()\n        {\n            InitializeComponent();\n        }\n\n        private Languages _language;\n\n        public Languages Language\n        {\n            get { return _language; }\n            set\n            {\n                switch (value)\n                {\n                    case Languages.Arabic:\n                        {\n                            label1.Text = "\xd9\x85\xd8\xb1\xd8\xad\xd8\xa8\xd8\xa7\xd9\x8b";\n                            _language = value;\n                        }\n                        break;\n                    case Languages.English:\n                        {\n                            label1.Text = "Hello";\n                            _language = value;\n                        }\n                        break;\n                    case Languages.Japanese:\n                        {\n                            label1.Text = "Conechoa";\n                            _language = value;\n                        }\n                        break;\n                }\n            }\n        }\n    }\n\n    public class UserControlDesigner : System.Windows.Forms.Design.ControlDesigner\n    {\n        private DesignerActionListCollection lists;\n        public override DesignerActionListCollection ActionLists\n        {\n            get\n            {\n                if (lists == null)\n                {\n\n                    lists = new DesignerActionListCollection();\n                    lists.Add(new UserControlActioonList(this.Component));\n                }\n                return lists;\n            }\n        }\n    }\n\n    public class UserControlActioonList : DesignerActionList\n    {\n        private UserControl2 myUserControl;\n        private DesignerActionUIService designerActionSvc = null;\n\n        public UserControlActioonList(IComponent component)\n            : base(component)\n        {\n            this.myUserControl = (UserControl2)component;\n\n            this.designerActionSvc =\n              (DesignerActionUIService)GetService(typeof(DesignerActionUIService));\n        }\n\n        private PropertyDescriptor GetPropertyByName(string propName)\n        {\n            PropertyDescriptor prop = default(PropertyDescriptor);\n            prop = TypeDescriptor.GetProperties(myUserControl)[propName];\n            if (prop == null)\n            {\n                throw new ArgumentException("Invalid Property", propName);\n            }\n            else\n            {\n                return prop;\n            }\n        }\n\n        public override System.ComponentModel.Design.DesignerActionItemCollection GetSortedActionItems()\n        {\n            DesignerActionItemCollection item = new DesignerActionItemCollection();\n            item.Add(new DesignerActionHeaderItem(\n                       "\xd8\xa7\xd9\x84\xd9\x85\xd8\xb8\xd9\x87\xd8\xb1"));\n            item.Add(new DesignerActionPropertyItem(\n                       "BackColor", "\xd9\x84\xd9\x88\xd9\x86 \xd8\xa7\xd9\x84\xd8\xae\xd9\x84\xd9\x81\xd9\x8a\xd8\xa9", "Appearance", "Set background Color of the control"));\n            item.Add(new DesignerActionHeaderItem("\xd8\xaa\xd8\xad\xd8\xaf\xd9\x8a\xd8\xaf \xd8\xa7\xd9\x84\xd9\x84\xd8\xba\xd8\xa9"));\n            item.Add(new DesignerActionPropertyItem(\n                       "Language", "\xd8\xa7\xd9\x84\xd9\x84\xd8\xba\xd8\xa9", "Functions", "Set the language of the control"));\n            return item;\n        }\n\n        public Color BackColor\n        {\n            get { return this.myUserControl.BackColor; }\n            set { GetPropertyByName("BackColor").SetValue(myUserControl, value); }\n        }\n\n        public Languages Language\n        {\n            get { return this.myUserControl.Language; }\n            set { GetPropertyByName("Language").SetValue(myUserControl, value); }\n        }\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n