Source: http://www.newlifex.com/showtopic-167.aspx
Well, the attachment is really damaged, the original code I did not have, and then extract I also have no energy, sorry, who has been under can be re-sent again? But even if not, you can refer to the following examples to be done quickly ...
Recently in a project, the business is more cumbersome, users need to customize the database, that is, stone open-source Rubik's Cube provides the functionality, but WinForm implementation of custom forms, this ...
Search the online previous code to find the following reference meanings:
Http://www.codeproject.com/Articles/24385/Have-a-Great-DesignTime-Experience-with-a-Powerful
Http://www.codeproject.com/Articles/60175/The-DesignSurface-Extended-Class-is-Back-Together
Http://www.cnblogs.com/michael-zhang/articles/655267.html
Http://www.cnblogs.com/pvistely/archive/2006/02/09/327656.html
But the function is not very comprehensive, the similarities are in the SD extract, haha.
To integrate these examples, found that the most important features of the design of the serialization function of the form is not ah, and then re-read a SD3.2 source code to extract the XmlForm-related codes, and then re-modified with XML to LINQ again, such as, The interface is made up of DotNetBar components:
Because the whole editor is associated with too many things, so I only put the core features out, interested friends can see, because of the time, menu commands I only added a limited number of, complete can add themselves to see the effect, all in the source code.
There are custom properties in the resource file Properties.xml settings, because I use a multi-language package, so in the source code to share the block of some code, in the Hmcustomproperty class set up, we will understand.
In addition, if some of the control's property objects are complex, this property needs to be serialized separately, which needs to be set separately in the Getelementfor method of the Designsurfaceext class and the SetAttributes method of the XMLLoader class. I'm using Sharpserializer to implement the Property object serialization.
There are more complex controls such as TabControl, but also need to set their own, you can look at the SD source code to see.
Another problem is not resolved, if you use shortcut keys in the design form, I extract the Formkeyhandler class in SD, there is a problem, I press the DEL key to delete a control when there is no problem, but in the property to edit a property will also use the DEL key, The selected controls in the design form are also removed,
The. NET version uses 2.0, so you need to manually add System.Core.dll and System.Xml.Linq.dll references, as well as newlife.core.dll references.
Here is the source code I uploaded, run-time:
*******************************************************
Package corruption is missing a file EventBindingService.cs, now the attachment can not be uploaded, their own name space to
Using System;Using System.Collections;Using System.ComponentModel;Using System.reflection;namespace hmframework.ui.sprite.services{InternalClass eventbindingserviceext:system.componentmodel.design.eventbindingservice{PublicEventbindingserviceext (IServiceProvider Provider):Base (provider) {}ProtectedOverride StringCreateuniquemethodname (IComponent component, EventDescriptor e) {Return String.Format ("{0}_{1}", Char.ToUpper (component. site.name[0]) + component. Site.Name.Substring (1), e.displayname);}Sohuld look around in form class for compatiable methodesProtectedOverride ICollectionGetcompatiblemethods (EventDescriptor e) {ArrayList Al =New ArrayList (); MethodInfo MethodInfo = E.eventtype.getmethod ("Invoke");if (Null! = MethodInfo) {al. ADD (methodinfo.name);}Return al;}ProtectedOverride BooleanShowCode () {Iworkbenchwindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow;if (window = = null) {return false;//}Formsdesignerviewcontent formdesigner = window. Activeviewcontent as Formsdesignerviewcontent;if (Formdesigner! = null) {Formdesigner.showsourcecode ();return true;//}Returnfalse;}ProtectedOverride BooleanShowCode (Int32 linenumber) {Iworkbenchwindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow;//if (window = = null) {//return false; }//formsdesignerviewcontent formdesigner = window. Activeviewcontent as Formsdesignerviewcontent; //if (Formdesigner! = null) {//Formdesigner.showsourcecode ( linenumber); //return true; //} return FALSE;} protected override Boolean ShowCode (IComponent component, EventDescriptor Edesc, String methodName) {// System.Windows.Forms.MessageBox.Show ("To add:" + component. Site.name + "\ r \ n" + methodName); return false;}}
-
New.png (94.08 K, download number: 2)
(2013/8/13 15:24:02 upload)
-
Designer.png (133.23 K, download number: 8)
(2013/8/13 15:24:02 upload)
WinForm custom Form (GO)