1
//-----------------------------------------------
2
父窗口代码
3
4
//-----------------------------------------------
5
public Main()
6
{
7
InitializeComponent();
8
//启用Windows XP视觉样式
9
Application.EnableVisualStyles();
10
11
12
//创建子窗体实例
13
WindowsApplication1.ListBoxSample child = new WindowsApplication1.ListBoxSample(this);
14
15
//显示子窗体
16
17
child.Show();
18
19
20
21
}
22
23
//-----------------------------------------------
24
子窗口代码
25
26
//-----------------------------------------------
27
public ListBoxSample(WindowsApplication1.Main parent)
28
{
29
InitializeComponent();
30
31
//指定父窗口对象
32
this.MdiParent = parent;
33
34
GetListItems(checkedListBox1);
35
}
36
37
38
//-----------------------------------------------
39
子窗口重载
40
41
//-----------------------------------------------
42
43
private void listBoxSample1ToolStripMenuItem_Click(object sender, EventArgs e)
44
{
45
46
Form fm=new ListBoxSample(this);
47
fm.Show();
48
49
}
50
51
//-----------------------------------------------
52
父子窗口中的菜单设置
53
54
//-----------------------------------------------
55
父窗口
56
&File的MergeAction属性=Replace
57
子窗口
58
&File的MergeAction=MatchOnly
59
工具栏的AllowMerge=false
60
61
62
63
//-----------------------------------------------
64
MDI窗口选项设置
65
66
//-----------------------------------------------
67
menuStrip1的属性MdiWindowListItem指向Windows菜单
68
69
如果要在菜单上创建平铺和前后的效果,添加两个菜单项,然后使用如下代码:
70
71
private void 平铺ToolStripMenuItem_Click(object sender, EventArgs e)
72
{
73
LayoutMdi(MdiLayout.TileHorizontal);
74
}
75
76
private void 前后ToolStripMenuItem_Click(object sender, EventArgs e)
77
{
78
LayoutMdi(MdiLayout.Cascade);
79
}

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

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79
