Net-informations.com
SiteMap  | About    

C# CheckBox Control

CheckBoxes allow the user to make multiple selections from a number of options. CheckBox to give the user an option, such as true/false or yes/no. You can click a check box to select it and click it again to deselect it.

C# checkbox

The CheckBox control can display an image or text or both. Usually CheckBox comes with a caption, which you can set in the Text property.

  checkBox1.Text = "Net-informations.com";

You can use the CheckBox control ThreeState property to direct the control to return the Checked, Unchecked, and Indeterminate values. You need to set the check boxs ThreeState property to True to indicate that you want it to support three states.

  checkBox1.ThreeState = true;

The radio button and the check box are used for different functions. Use a radio button when you want the user to choose only one option.When you want the user to choose all appropriate options, use a check box. The following C# program shows how to find a checkbox is selected or not.




using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string msg = "";

            if (checkBox1.Checked == true)
            {
                msg = "net-informations.com";
            }

            if (checkBox2.Checked == true)
            {
                msg = msg + "   vb.net-informations.com";
            }

            if (checkBox3.Checked == true)
            {
                msg = msg + "   csharp.net-informations.com";
            }


            if (msg.Length > 0)
            {
                MessageBox.Show (msg + " selected ");
            }
            else
            {
                MessageBox.Show ("No checkbox selected");
            }

            checkBox1.ThreeState = true;
        }
    }
}




net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.