WinForm中Component Class、User Control及Custom Control的区别和使用
来源:互联网 发布:淘宝助理数据包格式 编辑:程序博客网 时间:2024/05/21 06:54
1、 Component Class
Component Class可以从任何现有的 Windows 窗体控件继承产生新的控件。此方法使您得以保留 Windows 窗体控件所有固有功能,然后通过添加自定义属性、方法或其他功能扩展此固有功能。例如,可以创建一个从 TextBox 继承的控件,该控件只接受数字并能自动将输入转换为值。这样的控件可能包含验证代码,每当文本框中的文本发生更改时就会调用此代码,另外,控件还可能有一个附加的“值”属性。在某些控件中,也可以通过重写基类的 OnPaint 方法将自定义外观添加到控件的图形接口上。
处于下列情况时继承 Windows 窗体控件:
- 大多数所需的功能已经与现有的 Windows 窗体控件相同。
- 不需要自定义图形接口,或者想为现有控件设计一个新的图形前端。
2、User Control
用户控件是封装在公共容器内的 Windows 窗体控件的集合。此容器包含与每个 Windows 窗体控件相关联的所有固有功能,允许您有选择地公开和绑定它们的属性。用户控件的例子之一可能是已生成的显示数据库中客户地址数据的控件。该控件可能包括几个用来显示字段的文本框,几个用来通过记录定位的按钮 (Button) 控件。可以有选择地公开数据绑定属性,可以将整个控件打包并在应用程序之间重复使用。
处于下列情况时使用 UserControl :
- 要将若干个 Windows 窗体控件的功能合成一个可重新使用的单元。
3、 Custom Control
Custom Control是通过从 Control 继承来完全从头地创建一个控件。Control 类提供控件(例如事件)所需的所有基本功能,但不提供控件特定的功能或图形接口。与通过从用户控件或现有 Windows 窗体控件继承来创建控件相比,通过从 Control 类继承来创建控件需要耗费的心思和精力要多得多。因为作者必须为控件的 OnPaint 事件编写代码以及所需的任何功能特定代码,但同时也允许作者根据自己的需要,灵活地自定义调整控件。时钟控件即是一个自定义控件,它复制模拟时钟的外观和操作,自定义绘图将被调用来促使时钟指针走动,以响应内部计时器组件的 Tick 事件。
处于下列情况时使用Custom Control:
- 想要提供控件的自定义图形化表示形式。
- 需要实现无法从标准控件获得的自定义功能。
- WinForm中Component Class、User Control及Custom Control的区别和使用建议
- WinForm中Component Class、User Control及Custom Control的区别和使用
- WinForm中Component Class、User Control及Custom Control的区别和使用
- WinForm中Component Class、User Control及Custom Control的区别和使用
- WinForm中Component Class、User Control及Custom Control的区别和使用
- WinForm中Component Class、User Control及Custom Control的区别和使用
- C#中Component Class、User Control及Custom Control的区别
- C#中Component Class、User Control及Custom Control的区别
- 【PB】PB中object,control,custom class,custom visual,custom external等概念的区别
- 【PB】PB中object,control,custom class,custom visual,custom external等概念的区别
- Component和Control区别
- windows metro中Custom Control的开发和使用
- ClassLibary和WPF User Control LIbary和WPF Custom Control Libary的异同
- Custom Control控件的使用
- Custom Control 控件的使用
- Repeater或者DataList中如果要使用Custom User Control可以使用如下方法
- custom control的使用方法
- 自定义控件(custom control)的使用
- rar密码恢复之尝试
- 宽带一定是有线的[任正非]
- 第一回:恩怨情仇:is和as
- Posix线程编程指南(5)
- Winform 水印TextBox(近乎完美)
- WinForm中Component Class、User Control及Custom Control的区别和使用
- Informatica PMCMD 命令格式
- Web Service
- 简单对象访问协议-CNXML标准教程(SOAP)
- 走西口15集
- ASP.NET架构简介
- 如何在Ubuntu上安装Mercurial的最新版本
- 1月8日火箭vs凯尔特人
- 关于《Ajax实战:实例详解》与《Ajax实战》