我试图将一组四个单选按钮添加到窗体。还有其他单选按钮,因此我将它们放在面板上进行分组。但是,使用下面的内容,我只是将面板添加到了表单中,而没有单选按钮...我在这里做错了吗?
Dim arrRButton(3) As RadioButton
arrRButton(0) = New RadioButton
arrRButton(1) = New RadioButton
arrRButton(2) = New RadioButton
arrRButton(3) = New RadioButton
With arrRButton(0)
.AutoSize = True
.Checked = True
.Location = New System.Drawing.Point(77, 139)
.Name = "RadioButton5"
.Size = New System.Drawing.Size(55, 17)
.TabIndex = 48
.TabStop = True
.Text = "NEAR"
.UseVisualStyleBackColor = True
End With
'.... etc
'Panel2
Dim Panel2 As New Panel
With Panel2
.Controls.Add(arrRButton(0))
.Controls.Add(arrRButton(1))
.Controls.Add(arrRButton(2))
.Controls.Add(arrRButton(3))
.Location = New System.Drawing.Point(61, 130)
.Name = "Panel2"
.Size = New System.Drawing.Size(300, 24)
End With
Me.Controls.Add(Panel2)
最佳答案
如果要向表单添加一组单选按钮,请使用RadioButtonGroup
,而不要使用单选按钮数组。
关于vb.net - 以编程方式将控件添加到面板,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3219155/