Skip to content
Related Articles

Related Articles

Improve Article
How to set the font of the CheckBox in C#?
  • Last Updated : 25 Jun, 2019

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. In CheckBox, you are allowed to set the font of the text displayed in the CheckBox using the Font property of the CheckBox. It makes your CheckBox more attractive.
This property is an ambient property means if we do not set the value of this property, then it will be retrieved from the parent control. In Windows form, you can set this property in two different ways:

1. Design-Time: It is the simplest way to set the Font property of a CheckBox using the following steps:

  • Step 1: Create a windows form as shown in the below 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 font of the text displayed in CheckBox using Font property.

    Output:

2. Run-Time: It is a little bit trickier than the above method. In this method, you can set the Font property of a CheckBox programmatically using the following syntax:

public virtual System.Drawing.Font Font { get; set; }

Here, the Font is the type of font applied to the CheckBox content. Following steps are used to set the Font 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 Font property of the CheckBox provided by the CheckBox class.
    // Set the Font property of the CheckBox
    Mycheckbox.Font = new Font("Bradley Hand ITC", 12);
    
  • Step 3 : And last add this checkbox control to form using Add() method.
    // Add this checkbox to form
    this.Controls.Add(Mycheckbox);
    

    Example:




    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
      
    namespace WindowsFormsApp5 {
      
    public partial class Form1 : Form {
      
        public Form1()
        {
            InitializeComponent();
        }
      
        private void Form1_Load(object sender, EventArgs e)
        {
            // Creating and setting the properties of label
            Label l = new Label();
            l.Text = "Select language:";
            l.AutoSize = true;
            l.Location = new Point(233, 111);
            l.Font = new Font("Bradley Hand ITC", 12);
            // Adding lable to form
            this.Controls.Add(l);
      
            // Creating and setting the properties of CheckBox
            CheckBox Mycheckbox = new CheckBox();
            Mycheckbox.Height = 50;
            Mycheckbox.Width = 100;
            Mycheckbox.Location = new Point(229, 136);
            Mycheckbox.Text = "C#";
            Mycheckbox.BackColor = Color.LightPink;
            Mycheckbox.ForeColor = Color.DarkGreen;
            Mycheckbox.Name = "First_Check_Box";
            Mycheckbox.Font = new Font("Bradley Hand ITC", 12);
      
            // Adding checkbox to form
            this.Controls.Add(Mycheckbox);
      
            // Creating and setting the properties of CheckBox
            CheckBox Mycheckbox1 = new CheckBox();
            Mycheckbox1.Height = 50;
            Mycheckbox1.Width = 100;
            Mycheckbox1.Location = new Point(250, 198);
            Mycheckbox1.Text = "Ruby";
            Mycheckbox1.BackColor = Color.LightGreen;
            Mycheckbox1.ForeColor = Color.DeepPink;
            Mycheckbox1.Name = "Second_Check_Box";
            Mycheckbox1.Font = new Font("Bradley Hand ITC", 12);
      
            // Adding checkbox to form
            this.Controls.Add(Mycheckbox1);
        }
    }
    }

    Output:
     class=




My Personal Notes arrow_drop_up
Recommended Articles
Page :