C#仿QQ皮肤-GroupBox 控件实现(一)
2010-10-06 09:48 苏飞 阅读(6780) 评论(12) 编辑 收藏 举报阅读全文:http://www.sufeinet.com/thread-2104-1-1.html
这一次我们先要研究一下系统的是怎么完成的
我们使用Reflector反编译一下GroupBox一起来看看它的内部是怎么实现的。
从类的开始第一行我们可以看得出来它是继承Control这个类而来的,下面是所有引用的命名空间和继承的源

using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Text;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Windows.Forms.Internal;
using System.Windows.Forms.Layout;
using System.Windows.Forms.VisualStyles;
[DefaultEvent("Enter"), Designer("System.Windows.Forms.Design.GroupBoxDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), ClassInterface(ClassInterfaceType.AutoDispatch), DefaultProperty("Text"), ComVisible(true), System.Windows.Forms.SRDescription("DescriptionGroupBox")]
public class GroupBox : Control
{
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Text;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Windows.Forms.Internal;
using System.Windows.Forms.Layout;
using System.Windows.Forms.VisualStyles;
[DefaultEvent("Enter"), Designer("System.Windows.Forms.Design.GroupBoxDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), ClassInterface(ClassInterfaceType.AutoDispatch), DefaultProperty("Text"), ComVisible(true), System.Windows.Forms.SRDescription("DescriptionGroupBox")]
public class GroupBox : Control
{
其实这里告诉我们这样几个问题
1.所有引用的命名空间
2.默认的事件 DefaultEvent("Enter"),
3.在实现设计时服务的类 System.Windows.Forms.Design.GroupBoxDesigner
4.为Com指定接口类型ClassInterface
5.默认的属性DefaultProperty("Text")
6.托管类型或是成员的Com可访问性ComVisible
7.继承自 public class GroupBox : Control
关于事件的注册
我们以一个AutoSizeChanged事件来说明
EditorBrowsable(EditorBrowsableState.Always)
用上面的语句指定属性和方法是否在编辑器里的可见方式 在这里我们合作Always代表是编辑器里是始终可见的
然后让它显示在属性窗口中
阅读全文:http://www.sufeinet.com/thread-2104-1-1.html
本人的博客不再维护从2013年就不再维护了
需要我帮助的朋友请到我的个人论坛 http://www.sufeinet.com 进行讨论,感谢大家对我的支持!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?