Attach components to GroupBox in C#

zack picture zack · Sep 11, 2009 · Viewed 38.1k times · Source

I want to insert a group box in the form and put in 3 radio buttons in it.

Are there any advantages in attaching the 3 radio buttons to the groupbox.? Cab we even do that?

If I have to do it how do i attach the 3 radio buttons to the groupbox so that they become part of the group box and not separate components on the form?

Answer

Fredrik Mörk picture Fredrik Mörk · Sep 11, 2009

If you are talking winforms; simply drag the radio button controls into the GroupBox in the forms designer. If you want to add them programmatically, something like this should work:

RadioButton rb = new RadioButton();
rb.Text = "Some text";
myGroupBox.Controls.Add(rb);
rb.Location = new Point(someX, someY);

// repeat as necessary