UserControl Control 区别

Control是创建一个新的控件,自定义外观及行为
UserControl是由已有的控件组合出一个新的控件

UserControl继承Control
继承关系:
System.Object
      System.MarshalByRefObject
            System.ComponentModel.Component
                  System.Windows.Forms.Control
                        System.Windows.Forms.ScrollableControl
                              System.Windows.Forms.ContainerControl
                                    System.Windows.Forms.UserControl

继承Control的大量工作是如何绘制,
继承UserControl的主要工作是如何组合。

比如你想让你的Button有XP那样的风格,那你除了继承Button之外,就要考虑从Control继承(当然工作量和灵活性都会有很大区别)。写一个新的控件最好就是从Control继承。

以下是微软站点的资料:

自定义控件:通过调用 Paint 事件中的 Graphics 对象来显示 UI 的控件。自定义控件通常从 Control 派生。Chart 控件是自定义控件的一个示例。对创建自定义控件提供有限的设计时支持。  

用户或复合控件:由其他控件组成的控件。用户控件从 UserControl 派生。使用 TextBox 控件显示客户地址的控件是用户控件的一个示例。对使用 Visual Studio .NET Windows 窗体设计器创建用户控件提供完全设计时支持。  

posted @ 2011-04-10 08:07  surfshark  阅读(829)  评论(0编辑  收藏  举报