views:

23

answers:

2

I'm trying to add a group of four radio buttons to a form. There are other radio buttons so I'm grouping them by placing them on a Panel. However using the below I just get the panel added to the form without the radio buttons... Am I doing something wrong here?

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)
+1  A: 

If you want to add a group of radio buttons to a form, use RadioButtonGroup, not an array of radio buttons.

Oded
+1  A: 

.Size = New System.Drawing.Size(300, 24)

There's your problem, you made the panel too small. The first radio button's Location is at (77, 139), you'll have to set the panel's height to at least 139 + 17 = 156 to see it in full.

Here's a trick to get this kind of code right. In the Solution Explorer window, locate the "Show All Files" icon and click it. That shows all files in your solution. A node appears next to your form. Click it and double-click the .Designer.vb file. Locate the InitializeComponent() method. Observe how this code changes as you drop controls on the form and set their properties. Copy and paste code from this.

Using a UserControl can also be useful.

Hans Passant
+3: One for each paragraph.
AMissico