A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/c-sharp/radiobutton-in-c-sharp/ below:

RadioButton in C# - GeeksforGeeks

RadioButton in C#

Last Updated : 12 Jul, 2025

In Windows Forms, RadioButton control is a Graphical User Interface (GUI) used to select a single option among the group of options. For example, select a gender from the given list, so choose only one option among three options like Male or Female or Others. When we select a radio button any previously selected radio will be automatically deselected from the same group.

In Windows Forms, The radio button is part of the System.Windows.Forms namespace. These are the common key features of the radio button:

Ways to Create a Radio Button In Windows Forms

There are mainly two ways to create a radio button in Windows forms which are mentioned below.

Drag and drop ( Design-Time)

This is the easiest way to create a radio button in Windows Forms using Visual Studio we just have to open the toolbox and drag and drop the button on the form in the designer and further we can change the appearance of the radio button using the properties. Follow these steps to create a radio button.

Step 1: Now locate the project with the name here we are using the default name which is Form1 and it will open a form in the editor that we can further modify.

In the image, we have two files that are open one Design and there is Form1.cs these two play a major role. We use the Form 1.cs file for the custom logic.

Step 2: Now open a Toolbox go to the view > Toolbox or ctrl + alt + x.

Step 3. Now open the common controls and drag and drop the RadioButton on the form where we want to it be placed.

Step 4. Now open the properties of the button press right-click on the button and it will open the properties solution explorer now we can change the button name to Click here.

Here, we can also add different labels and radio buttons and further change their properties.

Output:

Custom Button (Run Time)

In this method, we are going to modify the Form1.cs file and add custom code modification in C# with the help of the RadioButton class. The following steps show how to create a RadioButton dynamically:

Step 1: Create a radio button using the RadioButton() constructor provided by the RadioButton class.

// Creating radio button

RadioButton r1 = new RadioButton();

Step 2: After creating the RadioButton, set the properties of the RadioButton provided by the RadioButton class.

// Set the AutoSize property

r1.AutoSize = true;

// Add text in RadioButton

r1.Text = "Intern";

// Set the location of the RadioButton

r1.Location = new Point(286, 40);

// Set Font property

r1.Font = new Font("Berlin Sans FB", 12);

Step 3: And last add this RadioButton control to the form using Add() method.

// Add this radio button to the form

this.Controls.Add(r1);

Step 4: Now double-click on the button in Design and it will open the Form cs file where code is written in C#. Here the program file is Form 1.cs Now write this code in Form1.cs file

Form1.cs file:

C#
namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            // Creating and setting label
            Label l = new Label();
            l.AutoSize = true;
            l.Location = new Point(176, 40);
            l.Text = "Select Post:";
            l.Font = new Font("Berlin Sans FB", 12);

            // Adding this label to the form
            this.Controls.Add(l);

            // Creating and setting the 
            // properties of the RadioButton
            RadioButton r1 = new RadioButton();
            r1.AutoSize = true;
            r1.Text = "Intern";
            r1.Location = new Point(286, 40);
            r1.Font = new Font("Berlin Sans FB", 12);

            // Adding this label to the form
            this.Controls.Add(r1);

            // Creating and setting the 
            // properties of the RadioButton
            RadioButton r2 = new RadioButton();
            r2.AutoSize = true;
            r2.Text = "Team Leader";
            r2.Location = new Point(356, 40);
            r2.Font = new Font("Berlin Sans FB", 12);
            // Adding this label to the form
            this.Controls.Add(r2);

            // Creating and setting the 
            // properties of the RadioButton
            RadioButton r3 = new RadioButton();
            r3.AutoSize = true;
            r3.Text = "Software Engineer";
            r3.Location = new Point(480, 40);
            r3.Font = new Font("Berlin Sans FB", 12);

            // Adding this label to the form
            this.Controls.Add(r3);

        }

    }
}

Output:

Properties Property Description Appearance This property is used to set a value determining the appearance of the RadioButton. AutoCheck This property is used to set a value indicating whether the Checked value and the appearance of the RadioButton control automatically change when the RadioButton control is clicked. AutoSize This property is used to set a value that indicates whether the RadioButton control resizes based on its contents. BackColor This property is used to set the background colour of the RadioButton control. CheckAlign This property is used to set the location of the check box portion of the RadioButton. Checked This property is used to set a value indicating whether the RadioButton control is checked. Font This property is used to set the font of the text displayed by the RadioButton control. ForeColor This property is used to set the foreground colour of the RadioButton control. Location This property is used to set the coordinates of the upper-left corner of the RadioButton control relative to the upper-left corner of its form. Name This property is used to set the name of the RadioButton control. Padding This property is used to set padding within the RadioButton control. Text This property is used to set the text associated with this RadioButton control. TextAlign This property is used to set the alignment of the text on the RadioButton control. Visible This property is used to set a value indicating whether the RadioButton control and all its child controls are displayed. Events Event Description Click This event occurs when the RadioButton control is clicked. CheckedChanged This event occurs when the value of the Checked property changes. AppearanceChanged This event occurs when the Appearance property value changes. DoubleClick This event occurs when the user double-clicks the RadioButton control. Leave This event occurs when the input focus leaves the RadioButton control. MouseClick This event occurs when the RadioButton control is clicked by the mouse. MouseDoubleClick This event occurs when the user double-clicks the RadioButton control with the mouse. MouseHover This event occurs when the mouse pointer rests on the RadioButton control. MouseLeave This event occurs when the mouse pointer leaves the RadioButton control.

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4