Examples with checkBox:-


Add a new Form i.e.,FormCheckBox1 to the Windows Application WABasics
Create one label,one checkBox & set the following properties to them

label1:-

Name          :         lblDisplay
Text            :         lblDisplay
Autosize     :         False[to increase the label size]
BackColor  :         ActiveCaption

Design :-


Generate the Event Handler for CheckChanged Event
Goto source & write the following code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WABasics
{
    public partial class FormCheckBox1 : Form
    {
        public FormCheckBox1()
        {
            InitializeComponent();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
                lblDisplay.Text = "Check Box is Checked";
            // MessageBox.Show("Check Box is Checked");

            else
                lblDisplay.Text = "CheckBox is Un-Checked";
               // MessageBox.Show("The Check Box is Un-Checked");
        }
    }
}




Result :-

Example2 with CheckBox:-
Add a new Form i.e.,FormCheckBox2 to the Windows Application WABasics
Create three labels,one textboxe and one buttons ,Four checkBoxes& set the following properties to them


label1:
     Text      : Enter YourName
     Name    : lblName


label2:
     Text     : Select Your Hobbies
     Name   : lblHobbies


label3:
     Name        :   lblDisplay
   AutoSize     :  True
   BackColor   :  Menu Highlight




textBox1:
     Name   : txtName


button1:-

Name   :  btnSubmit
Text     :  Submit


checkBox1:
     Name   : chkPlaying
     Text     : Playing

checkBox2:
     Name   : chkReading
     Text     : Reading


checkBox3:
     Name   : chkBrowsing
     Text     : Browsing


checkBox4:
     Name   : chkTeaching
     Text     : Teaching



Design :-

Generate the EventHandler for btnSubmit button Click Event
& write the following code in Source[FormCheckBox2.cs] 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WABasics
{
    public partial class FormCheckBox2 : Form
    {
        public FormCheckBox2()
        {
            InitializeComponent();
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            string s = txtName.Text+" Hobbies Are ";
            if (chkBrowsing.Checked == true)
                s = s + chkBrowsing.Text + "   ";
            if (chkPlaying.Checked == true)
                s = s + chkPlaying.Text + "  ";
            if (chkReading.Checked == true)
                s = s + chkReading.Text + " ";
            if (ChkTeaching.Checked == true)
                s = s + ChkTeaching.Text;
            lblDisplay.Text = s;

        }

       
    }
}



Result :-



No comments:

Post a Comment