vb.net控件详解 vbnet控件大全( 六 )


当我们调整GroupBox控件所包含的控件的Anchor和Dock属性的时候 其参照物将不是Form窗体 而是GroupBox控件了
三 编程添加GroupBox控件以及它所包含的控件
虽然GroupBox控件是在设计时用视图设计布局效果最好 但是无可避免地 很多特殊情况下也是需要在运行做添加控件到控件组中的 这里我们就用代码来完成上图一界面的绘制
动态添加控件一般需要经过下面三个步骤
创建要添加的控件实例
设置新控件的属性
将控件添加到父控件的 Controls 集合
在Form 代码的任意位置增加初始化控件的过程InitializeControl() 代码如下所示
Sub InitializeControl()
首先添加Label和TextBox控件
Dim Label As New System Windows Forms Label
Dim TextBox As New System Windows Forms TextBox
Label
Label Location = New System Drawing Point( )
Label Name = Label
Label Size = New System Drawing Size( )
Label TabIndex =
Label Text = 户主姓名
TextBox
TextBox Location = New System Drawing Point( )
TextBox Name = TextBox
TextBox Size = New System Drawing Size( )
TextBox TabIndex =
TextBox Text =
把它们添加到父控件Form 的Controls集合中
Me Controls Add(TextBox )
Me Controls Add(Label )
添加三个GroupBox控件
Dim GroupBox As New System Windows Forms GroupBox
Dim GroupBox As New System Windows Forms GroupBox
Dim GroupBox As New System Windows Forms GroupBox
GroupBox
GroupBox BackColor = System Drawing SystemColors Control
GroupBox Location = New System Drawing Point( )
GroupBox Name = GroupBox
GroupBox Size = New System Drawing Size( )
GroupBox TabIndex =
GroupBox TabStop = False
GroupBox Text = 性别
GroupBox
GroupBox Location = New System Drawing Point( )
GroupBox Name = GroupBox
GroupBox Size = New System Drawing Size( )
GroupBox TabIndex =
GroupBox TabStop = False
GroupBox Text = 单元
GroupBox
GroupBox Location = New System Drawing Point( )
GroupBox Name = GroupBox
GroupBox Size = New System Drawing Size( )
GroupBox TabIndex =
GroupBox TabStop = False
GroupBox Text = 楼层
把它们添加到父控件Form 的Controls集合中
Me Controls Add(GroupBox )
Me Controls Add(GroupBox )
Me Controls Add(GroupBox )
添加RadioButton控件并分别绘制在GroupBox控件内
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
RadioButton
RadioButton Location = New System Drawing Point( )
RadioButton Name = RadioButton
RadioButton Size = New System Drawing Size( )
RadioButton TabIndex =
RadioButton Text = 男性
RadioButton
RadioButton Location = New System Drawing Point( )
RadioButton Name = RadioButton
RadioButton Size = New System Drawing Size( )
RadioButton TabIndex =
RadioButton Text = 女性
RadioButton
RadioButton Location = New System Drawing Point( )
RadioButton Name = RadioButton
RadioButton Size = New System Drawing Size( )
RadioButton TabIndex =
RadioButton Text = 二单元

推荐阅读