Wae*_*oul 6 .net c# vb.net components visual-studio
请看下面的图片,它显示了DataGridView的智能标记.
DataGridView智能标签http://img199.imageshack.us/img199/5871/post517531249536112.jpg
现在我正在创建一个新组件,我希望它支持在智能标记中显示一些属性.如何将属性添加到智能标记?
我使用了http://msdn.microsoft.com/en-us/library/default.aspx?q=smart+tag+windows+forms+designer.
因此,我发现了演练:将智能标记添加到Windows窗体组件.
执行相同搜索的任何人都会找到相同的文章.
更新:该链接不再有效.我刚刚尝试搜索"智能标记窗体表单设计器",并发现"演练:将智能标记添加到Windows窗体组件"作为第一个搜索命中.Google中的相同搜索显示"如何:将智能标记附加到Windows窗体组件"作为第一个匹配,但显示与第二次匹配相同的演练.
您可以使用以下代码查看自定义控件中的示例标记。
\n\n您可以从 www.windowsclient.com 获取有关该内容的视频。
\n\nusing 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