Winform自定义表单(转)

出处:http://www.newlifex.com/showtopic-167.aspx

好吧,附件真的损坏了,原始代码我也没有了,再提取我也没精力了,不好意思,哪位之前下过可以重发一遍吗?不过即使没有也可以参考下面几个示例很快就可以做出来了......

最近在做个项目,业务方面较繁琐,用户需要自定义数据库,也就是石头开源的魔方所提供的功能,但winform实现自定义表单,这个......
在网上搜索了前人的代码发现以下几个参考意义:
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

不过功能都不是很全面,相似之处都是在SD中提取的,哈哈。
把这几个例子整合了一下,发现还缺少最重要的功能对设计窗体的序列化功能都没有啊,于是重新翻阅了一个SD3.2的源代码把XmlForm相关的代码提取出来,然后用XML to Linq重新修改了一遍,效果图如下,界面是用dotnetbar组件:



由于整个编辑器关联太多东东,所以我只把核心功能提出出来,有兴趣的朋友可以看看,由于时间关系,菜单命令我只添加了有限的几个,完整的可以自己添加看看效果,全在源代码中。
还有自定义属性在资源文件中Properties.xml设置,由于我用的是多语言包的,所以在分享的源代码中屏蔽了部分代码,在HmCustomProperty类中进行设置,大家看看就会懂的。

另外如果有些控件的属性对象复杂的话,需要对这个属性单独进行序列化,需要在DesignSurfaceExt类的GetElementFor方法和XmlLoader类的SetAttributes方法中分别设置,我用的是SharpSerializer来实现属性对象序列化的。

还有就是比较复杂的控件如Tabcontrol之类的,也需要自己单独设置,大家可以查看一下sd的源代码看看。

还有一个问题没有解决,如果在设计窗体中使用快捷键,我把sd中的FormKeyHandler类提取出来,就会有一个问题,我按del键删除一个控件时没有问题,但是在在属性中编辑某个属性时也会用到del键,这时也会把设计窗体中的选中的控件删除,

.net版本用的是2.0,所以需要手动添加system.core.dll和system.xml.linq.dll的引用,还有newlife.core.dll的引用。

下面是我上传的源代码,运行时的截图:


*******************************************************
压缩包损坏缺少一个文件EventBindingService.cs,现在附件上传不了啦,自己该下命名空间把
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, 下载次数:2)

(2013/8/13 15:24:02 上传)

 

new.png

designer.png  (133.23 K, 下载次数:8)

(2013/8/13 15:24:02 上传)

 

designer.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值