Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GroupBox contain controls,how to get the names of those controls?

Tags:

c#

.net

winforms

Im using GroupBox Control on my Form Page(WinForms).

The GroupBox contain five controls(RadioButtons).

Any idea how can I get the names and the states of controls inside GroupBox Control?

like image 281
Michael Avatar asked Nov 08 '12 14:11

Michael


1 Answers

You can use Enumerable.OfType to find and cast your RadioButtons in the GroupBox:

var radioButtons = groupBox1.Controls.OfType<RadioButton>();
foreach (RadioButton rb in radioButtons)
{
    bool state = rb.Checked;
    string name = rb.Name;
}
like image 170
Tim Schmelter Avatar answered Nov 18 '22 01:11

Tim Schmelter