代码改变世界

C#仿QQ皮肤-GroupBox 控件实现(一)

  苏飞  阅读(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
    {
复制代码

 

其实这里告诉我们这样几个问题

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

 

 


(评论功能已被禁用)
编辑推荐:
· 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,谁才是开发者新宠?
点击右上角即可分享
微信分享提示