Category:c#
Article From:https://www.cnblogs.com/smileberry/p/9122299.html

Source: http://www.newlifex.com/showtopic-167.aspx

All right, the attachment is really damaged, and I have no original code. I have no energy to extract it again. Sorry, who has been able to repeat it before? But if not, you can refer to the following examples, which can be done soon.

In the recent project, the business is tedious, users need to customize the database, that is, the function provided by the stone open – source magic cube, but WinForm implements a custom form, this…
Searching for the code of predecessors on the Internet found 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 extracted from SD, ha ha.
The integration of these examples, the lack of the most important functions for the serialization of the design form, and re read a SD3.2 source code to extract the XmlForm related code, and then revise it with the XML to Linq, the effect mapAs follows, the interface is dotnetbar components:

Because the entire editor is too much related to East, so I only put forward the core function, interested friends can see, because of the time relationship, I only added a few limited menu commands, the complete can be added to see the effect of its own, all in the source code.
There are also custom properties in the Properties.xml settings in the resource file, because I use a multi – language package, so the source code is shielded in the shared source code, set in the HmCustomProperty class, you will see it.

In addition, if the attribute objects of some controls are complex, it is necessary to serialize this property individually, which needs to be set in the GetElementFor method of the DesignSurfaceExt class and the SetAttributes method of the XmlLoader class.I use SharpSerializer to serialize attribute objects.

There are more complex controls such as Tabcontrol, and also need to set up their own separate, you can check the source code of SD to see.

One more problem is not solved. If I use the shortcut key in the design form, if I extract the FormKeyHandler class in SD, there will be a problem. I do not have a problem when I delete a control by the Del key, but the Del key is also used when editing a property in the property.At this time, the selected controls in the design form will also be deleted.

.netThe version is 2, so you need to manually add references to system.core.dll and system.xml.linq.dll, as well as newlife.core.dll references.

Below is the screenshot of my uploaded source code, run time:


*******************************************************
There is a missing file EventBindingService.cs missing from the compressed package. Now the attachments cannot be uploaded.

using System;
using System.Collections;
using System.ComponentModel;
using System.Reflection;

namespace HmFramework.UI.Sprite.Services
{
internal class EventBindingServiceExt : System.ComponentModel.Design.EventBindingService
{
public EventBindingServiceExt(IServiceProvider provider)
: base(provider)
{
}

protected override String CreateUniqueMethodName(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 methodes
protected override ICollection GetCompatibleMethods(EventDescriptor e)
{
ArrayList al = new ArrayList();
MethodInfo methodInfo = e.EventType.GetMethod("Invoke");
if (null != methodInfo)
{
al.Add(methodInfo.Name);
}
return al;
}

protected override Boolean ShowCode()
{
//IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow;
//if (window == null) {
// return false;
//}
//FormsDesignerViewContent formDesigner = window.ActiveViewContent as FormsDesignerViewContent;
//if (formDesigner != null) {
// formDesigner.ShowSourceCode();
// return true;
//}
return false;
}

protected override Boolean ShowCode(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, Number of downloads: 2)

(2013/8/13 15:24:02 Upload)

 

new.png

designer.png (133.23 K, Number of downloads: 8)

(2013/8/13 15:24:02 Upload)

 

designer.png

Link of this Article: Winform custom form (turn)

Leave a Reply

Your email address will not be published. Required fields are marked *