本文共 3002 字,大约阅读时间需要 10 分钟。
public class MyTextBoxDesigner : ControlDesigner { public override void Initialize(IComponent component) { IDesignerHost host = (IDesignerHost)component.Site.GetService(typeof(IDesignerHost)); ComponentTray tray = (ComponentTray)host.GetService(typeof(ComponentTray)); ........................ base.Initialize(component); } } |
public class MyTextBoxDesigner : ControlDesigner { public override void Initialize(IComponent component) { ................... if (tray == null) { IComponent comp = host.CreateComponent(typeof(MyComponent)); tray = (ComponentTray)host.GetService(typeof(ComponentTray)); if (tray == null) throw new SystemException("can't create component tray."); tray.AddComponent(component); host.DestroyComponent(comp); } else tray.AddComponent(component); base.Initialize(component); } } |
[ToolboxItem(false)] public class DummyComponent : Component { } |
using System; using System.ComponentModel; using System.ComponentModel.Design; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Windows.Forms.Design; namespace ClassLibrary1 { [Designer(typeof(MyTextBoxDesigner))] public class MyTextBox:TextBox { private string _information; public string Information { get { return _information; } set { _information = value; } } } [ToolboxItem(false)] public class MyComponent : Component { } public class MyTextBoxDesigner : ControlDesigner { public override void Initialize(IComponent component) { IDesignerHost host = (IDesignerHost)component.Site.GetService(typeof(IDesignerHost)); ComponentTray tray = (ComponentTray)host.GetService(typeof(ComponentTray)); if (tray == null) { IComponent comp = host.CreateComponent(typeof(DummyComponent)); tray = (ComponentTray)host.GetService(typeof(ComponentTray)); if (tray == null) throw new SystemException("can't create component tray."); tray.AddComponent(component); host.DestroyComponent(comp); } else tray.AddComponent(component); base.Initialize(component); } } } |
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1054420