第三章例题:为控件添加设计时支持
对教材3.3部分进行演示
完整源代码下载:control_runtime_attribute.rar
1
[ToolboxBitmap(@"E:\教学\基于C#的Windows应用程序设计\第三章\test_cra\App.ico")]
2
public class UserControl1 : System.Windows.Forms.UserControl
3
{
4
private System.Windows.Forms.Button button1;
5
private System.Windows.Forms.Button button2;
6
/// <summary>
7
/// 必需的设计器变量。
8
/// </summary>
9
private System.ComponentModel.Container components = null;
10
11
public UserControl1()
12
{
13
// 该调用是 Windows.Forms 窗体设计器所必需的。
14
InitializeComponent();
15
16
// TODO: 在 InitComponent 调用后添加任何初始化
17
18
}
19
20
/// <summary>
21
/// 清理所有正在使用的资源。
22
/// </summary>
23
protected override void Dispose( bool disposing )
24
{
25
if( disposing )
26
{
27
if( components != null )
28
components.Dispose();
29
}
30
base.Dispose( disposing );
31
}
32
33
[Browsable(true),Description("自定义的属性描述"),Category("自定义的分类")]
34
public Color Button1Color
35
{
36
set
37
{
38
button1.BackColor = value;
39
}
40
get
41
{
42
return button1.BackColor;
43
}
44
}
45
}
[ToolboxBitmap(@"E:\教学\基于C#的Windows应用程序设计\第三章\test_cra\App.ico")]2
public class UserControl1 : System.Windows.Forms.UserControl3
{4
private System.Windows.Forms.Button button1;5
private System.Windows.Forms.Button button2;6
/// <summary>7
/// 必需的设计器变量。8
/// </summary>9
private System.ComponentModel.Container components = null;10

11
public UserControl1()12
{13
// 该调用是 Windows.Forms 窗体设计器所必需的。14
InitializeComponent();15

16
// TODO: 在 InitComponent 调用后添加任何初始化17

18
}19

20
/// <summary>21
/// 清理所有正在使用的资源。22
/// </summary>23
protected override void Dispose( bool disposing )24
{25
if( disposing )26
{27
if( components != null )28
components.Dispose();29
}30
base.Dispose( disposing );31
}32

33
[Browsable(true),Description("自定义的属性描述"),Category("自定义的分类")]34
public Color Button1Color35
{36
set37
{38
button1.BackColor = value;39
}40
get41
{42
return button1.BackColor;43
}44
}45
}完整源代码下载:control_runtime_attribute.rar


浙公网安备 33010602011771号