Introduction
A RadioButton control provides a round interface to select one option from a number of options. Radio buttons are usually placed in a group on a container control, such as a Panel or a GroupBox, and one of them is selected.
Creating a RadioButton
We can create a RadioButton control using a Forms designer at design-time or using the RadioButton class in code at run-time (also known as dynamically).
To create a RadioButton control at design-time, you simply drag and drop a RadioButton control from Toolbox to a Form in Visual Studio. After you drag and drop a RadioButton on a Form, the RadioButton looks like Figure 1. Once a RadioButton is on the Form, you can move it around and resize it using the mouse and set its properties and events.

Creating a RadioButton control at run-time is merely the work of creating an instance of RadioButton class, setting its properties and adding RadioButton class to the Form controls.
The first step to create a dynamic RadioButton is to create an instance of RadioButton class. The following code snippet creates a RadioButton control object.
- RadioButton dynamicRadioButton = new RadioButton();
In the next step, you may set properties of a RadioButton control. The following code snippet sets location, width, height, background color, foreground color, Text, Name, and Font properties of a RadioButton.
- dynamicRadioButton.Left = 20;
- dynamicRadioButton.Top = 100;
- dynamicRadioButton.Width = 300;
- dynamicRadioButton.Height = 30;
- dynamicRadioButton.BackColor = Color.Orange;
- dynamicRadioButton.ForeColor = Color.Black;
- dynamicRadioButton.Text = "I am a Dynamic RadioButton";
- dynamicRadioButton.Name = "DynamicRadioButton";
- dynamicRadioButton.Font = new Font("Georgia", 12);
Once a RadioButton control is ready with its properties, the next step is to add the RadioButton control to the Form. To do so, we use Form.Controls.Add method. The following code snippet adds a RadioButton control to the current Form.
- Controls.Add(dynamicRadioButton);
The new RadioButton created by the above code looks like Figure 2.

Setting RadioButton Properties
After you place a RadioButton control on a Form, the next step is to set properties.
The easiest way to set properties is from the Properties Window. You can open Properties window by pressing F4 or right clicking on a control and selecting Properties menu item. The Properties window looks like Figure 3.

RadioButton Location, Height, Width, and Size
The Location property takes a Point that specifies the starting position of the RadioButton on a Form. You may also use Left and Top properties to specify the location of a control from the left top corner of the Form. The Size property specifies the size of the control. We can also use Width and Height property instead of Size property. The following code snippet sets Location, Width, and Height properties of a RadioButton control.
- dynamicRadioButton.Location = new Point(20, 150);
- dynamicRadioButton.Height = 40;
- dynamicRadioButton.Width = 300;
RadioButton Background, Foreground, BorderStyle
BackColor and ForeColor properties are used to set background and foreground color of a RadioButton respectively. If you click on these properties in Properties window, the Color Dialog pops up.
Alternatively, you can set background and foreground colors at run-time. The following code snippet sets BackColor and ForeColor properties.
- dynamicRadioButton.BackColor = Color.Red;
- dynamicRadioButton.ForeColor = Color.Blue;
RadioButton Name
Name property represents a unique name of a RadioButton control. It is used to access the control in the code. The following code snippet sets and gets the name and text of a RadioButton control.
- dynamicRadioButton.Name = "DynamicRadioButton";
- string name = dynamicRadioButton.Name;




Pankajkumar PatelPosted Aug 19, 2019, 12:16 AM
Good article
Suraj KumarPosted Jun 22, 2019, 3:10 AM
Dear sir, it's good article with example. I have one suggestion. Please separate the words privatevoid into private void in last line coding example.
Rushi MehtaPosted Sep 26, 2018, 7:43 AM
Nice Article
Yolgezer AragornPosted Mar 23, 2013, 5:13 PM
Thank you
Arun KurmiPosted Mar 15, 2013, 10:37 AM
Sir,When i tried below code to creating dynamic radiobutton it will generate an Exception: ArgumentException and give an messege: Top level control cannot be added to a control.And one more thing if i used same code for textbox then there is no problem.why? CheckAlign property also give an error. private void button1_Click(object sender, EventArgs e) { //Creation of dynamic radiobutton namely rdb(by creating a object of radiobutton class) RadioButton rdb = new RadioButton(); //TextBox rdb = new TextBox(); //Assign(set) properties to dyanicmic radiiobutyton rdb rdb.Width = 50; rdb.Height = 50; rdb.Left = 50; rdb.Top = 50; rdb.BackColor = Color.LightCyan; rdb.ForeColor = Color.Green; rdb.Text = "Male"; rdb.Name = "arun"; rdb.Font = new Font("Verdana", 14); //Add control to form Controls.Add(rdb); //rdb.CheckAlign = ContentAlignment.MiddleRight;