How to set the appearance of the CheckBox in C#?
The CheckBox control is the part of windows form which is used to take input from the user. Or in other words, CheckBox control allows us to select single or multiple elements from the given list. You are allowed to use a CheckBox as a normal CheckBox or a CheckBox as a button by using Appearance property provided by CheckBox class.
Appearance property is set to normal, then it behaves like the normal CheckBox and if the Appearance property set to the button, then it will work like a toggle button. By default value of this property is Normal. In Windows form, you can set this property in two different ways:
1. Design-Time: It is the simplest way to set the Appearance property of a CheckBox using the following steps:
- Step 1: Create a windows form as shown below in the image
Visual Studio -> File -> New -> Project -> WindowsFormApp

- Step 2: Drag the CheckBox control from the ToolBox and drop it on the windows form. You can place CheckBox anywhere on the windows form according to your need.

- Step 3: After drag and drop you will go to the properties of the CheckBox control to set the value of Appearance property.

Output:

2. Run-Time: It is a little bit trickier than the above method. In this method, you can set the Appearance property of a CheckBox programmatically using the following syntax:
public System.Windows.Forms.Appearance Appearance { get; set; }
It also throws an InvalidEnumArgumentException if the value assigned to this property is not from the Appearance values. Following steps are used to set the Appearance property of the CheckBox:
- Step 1: Create a checkbox using the CheckBox() constructor provided by the CheckBox class.
// Creating checkbox CheckBox Mycheckbox = new CheckBox();
- Step 2: After creating CheckBox, set the Appearance property of the CheckBox provided by the CheckBox class.
// Set the Appearance property of the CheckBox Mycheckbox.Appearance = Appearance.Normal;
- Step 3 : And last add this checkbox control to form using Add() method.
// Add this checkbox to form this.Controls.Add(Mycheckbox);
Example:
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceWindowsFormsApp5 {publicpartialclassForm1 : Form {publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender, EventArgs e){// Creating and setting the properties of labelLabel l =newLabel();l.Text ="Select language:";l.AutoSize =true;l.Location =newPoint(233, 111);l.Font =newFont("Bradley Hand ITC", 12);// Adding lable to formthis.Controls.Add(l);// Creating and setting the properties of CheckBoxCheckBox Mycheckbox =newCheckBox();Mycheckbox.Height = 50;Mycheckbox.Width = 100;Mycheckbox.Location =newPoint(229, 136);Mycheckbox.Text ="C#";Mycheckbox.Appearance = Appearance.Normal;Mycheckbox.Font =newFont("Bradley Hand ITC", 12);// Adding checkbox to formthis.Controls.Add(Mycheckbox);// Creating and setting the properties of CheckBoxCheckBox Mycheckbox1 =newCheckBox();Mycheckbox1.Height = 50;Mycheckbox1.Width = 100;Mycheckbox1.Location =newPoint(230, 198);Mycheckbox1.Text ="Ruby";Mycheckbox1.Appearance = Appearance.Button;Mycheckbox1.Font =newFont("Bradley Hand ITC", 12);// Adding checkbox to formthis.Controls.Add(Mycheckbox1);}}}chevron_rightfilter_noneOutput:

Recommended Posts:
- How to set the appearance of RadioButton in C#?
- CheckBox in C#
- How to set the name of the CheckBox in C#?
- How to set the Location of CheckBox in C#?
- How to set the state of the CheckBox in C#?
- How to set the AutoSize of the CheckBox in C#?
- How to set the padding of CheckBox in C#?
- How to set text in the CheckBox in C#?
- How to set the visibility of the CheckBox in C#?
- How to set the font of the CheckBox in C#?
- How to set the CheckBox to Checked state in C#?
- How to set the Margin between the CheckBox controls in C#?
- How to set the background color of the CheckBox in C#?
- How to set the alignment of Text in CheckBox in C#?
- How to set the foreground color of the CheckBox in C#?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



