第三章例题:为控件添加设计时支持
对教材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
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

完整源代码下载:control_runtime_attribute.rar