唉,我当初也是看的头晕,不过公司原因没有做下去,怀念那段日子呀,真想坚持做下去。http://www.52dotnet.com/form.jpghost = new DefaultDesignerHost(); ComponentChangeService changeService = new ComponentChangeService(); host.AddService(typeof(System.ComponentModel.Design.IComponentChangeService), changeService); host.AddService(typeof(System.ComponentModel.Design.IDesignerOptionService), new ICSharpCode.SharpDevelop.FormDesigner.Services.DesignerOptionService()); host.AddService(typeof(System.ComponentModel.Design.ITypeDescriptorFilterService), new TypeDescriptorFilterService());
host.AddService(typeof(System.Drawing.Design.IPropertyValueUIService), new PropertyValueUIService());
ExtenderService extenderService = new ExtenderService(); host.AddService(typeof(System.ComponentModel.Design.IExtenderListService), extenderService); host.AddService(typeof(System.ComponentModel.Design.IExtenderProviderService),extenderService);
host.AddService(typeof(System.ComponentModel.Design.IDesignerHost), host); host.AddService(typeof(System.ComponentModel.IContainer), host.Container); host.AddService(typeof(System.ComponentModel.Design.IDictionaryService), new DictionaryService()); host.AddService(typeof(System.ComponentModel.Design.IEventBindingService), new EventBindingService(host)); host.AddService(typeof(System.ComponentModel.Design.ISelectionService), new SelectionService(host));
host.AddService(typeof(System.ComponentModel.Design.Serialization.INameCreationService), new NameCreationService(host)); host.AddService(typeof(System.ComponentModel.Design.IDesignerEventService), new DesignerEventService()); host.AddService(typeof(System.ComponentModel.Design.IReferenceService), new ReferenceService(host)); host.AddService(typeof(System.ComponentModel.Design.Serialization.IDesignerSerializationService), new FormDesign.DesignerSerializationService(host));
// Add toolbox service host.AddService(typeof(IToolboxService), listView1); PopulateToolbox(listView1); host.Activate();
// host.TransactionClosed += new DesignerTransactionCloseEventHandler(TransactionFinished);
if (designPanel == null) { designPanel = new DesignPanel(host); } else { designPanel.Host = host; }
// host.AddService(typeof(System.ComponentModel.Design.IMenuCommandService), new MenuCommandService(host, designPanel));
host.AddService(typeof(DesignPanel), designPanel); host.AddService(typeof(System.ComponentModel.Design.IMenuCommandService), new CMConfig.MenuCommandService(host, designPanel)); designPanel.Location = new Point(0, 0); designPanel.Dock = DockStyle.Fill; // this.panel1.Controls.Add(designPanel); listView1.designPanel = designPanel;
在button_clicked或mouse_over等事件中,可以在button的周围用GDI+画你想要的东西了,你想画什么就画什么。
不但会出现八个 小白框,而且还像设计时一样,可以移动,可以移动改变控件的大小,
而且不限于 Button
呵呵,可惜,偶不记得在哪里看到的,偶还测试过
bool isDesign;
protected override void OnPaint(PaintEventArgs e){
if(isDesign){
//画设计状态
}
else{
//画普通状态
}
}isDesign改变的时候Invalidate()控件
1.利用Framework的自带的结构,有个例子,链接找不到了,用FormDesigner查应该可以查到
SharpDevelop用的也是这个,不过比较复杂,不易看懂
2.自己动手实现,虽然有点麻烦,不过还是不难的,这个也有程序可以参考,有本书叫<基于组件的开发>
第10章就是移动的例子,不过书有点贵我用的是第2种方式,他的好处是不依赖Framework,很方便支持图形组件的移动等
ComponentChangeService changeService = new ComponentChangeService();
host.AddService(typeof(System.ComponentModel.Design.IComponentChangeService), changeService);
host.AddService(typeof(System.ComponentModel.Design.IDesignerOptionService), new ICSharpCode.SharpDevelop.FormDesigner.Services.DesignerOptionService());
host.AddService(typeof(System.ComponentModel.Design.ITypeDescriptorFilterService), new TypeDescriptorFilterService());
host.AddService(typeof(System.Drawing.Design.IPropertyValueUIService), new PropertyValueUIService());
ExtenderService extenderService = new ExtenderService();
host.AddService(typeof(System.ComponentModel.Design.IExtenderListService), extenderService);
host.AddService(typeof(System.ComponentModel.Design.IExtenderProviderService),extenderService);
host.AddService(typeof(System.ComponentModel.Design.IDesignerHost), host);
host.AddService(typeof(System.ComponentModel.IContainer), host.Container);
host.AddService(typeof(System.ComponentModel.Design.IDictionaryService), new DictionaryService());
host.AddService(typeof(System.ComponentModel.Design.IEventBindingService), new EventBindingService(host));
host.AddService(typeof(System.ComponentModel.Design.ISelectionService), new SelectionService(host));
host.AddService(typeof(System.ComponentModel.Design.Serialization.INameCreationService), new NameCreationService(host));
host.AddService(typeof(System.ComponentModel.Design.IDesignerEventService), new DesignerEventService()); host.AddService(typeof(System.ComponentModel.Design.IReferenceService), new ReferenceService(host));
host.AddService(typeof(System.ComponentModel.Design.Serialization.IDesignerSerializationService), new FormDesign.DesignerSerializationService(host));
// Add toolbox service
host.AddService(typeof(IToolboxService), listView1); PopulateToolbox(listView1); host.Activate();
// host.TransactionClosed += new DesignerTransactionCloseEventHandler(TransactionFinished);
if (designPanel == null)
{
designPanel = new DesignPanel(host);
}
else
{
designPanel.Host = host;
}
// host.AddService(typeof(System.ComponentModel.Design.IMenuCommandService), new MenuCommandService(host, designPanel));
host.AddService(typeof(DesignPanel), designPanel); host.AddService(typeof(System.ComponentModel.Design.IMenuCommandService), new CMConfig.MenuCommandService(host, designPanel));
designPanel.Location = new Point(0, 0);
designPanel.Dock = DockStyle.Fill; // this.panel1.Controls.Add(designPanel); listView1.designPanel = designPanel;