Working with Checkbox in Windows Forms

by Jagadish Pulakhandam on 4/10/2011 2:05:52 PM
Rated 0 from 0 votes
Brief: This sample demonstrates Checkbox control in Windows Forms using C#.
Posted to: Microsoft Windows Forms - Checkbox
Add to DiggAdd to del.icio.usAdd to FURLAdd to RedditAdd to YahooAdd to BlinklistAdd to GoogleAdd to ma.gnoliaAdd to ShadowsAdd to Technorati

This sample demonstrates on how to use Checkbox in Windows Forms.  "Checked" is the main property (of Checkbox control) which returns a boolean value based on its selected status.

Following is the screen shot.



Following is the code:

01.using System;
02.using System.Collections.Generic;
03.using System.ComponentModel;
04.using System.Data;
05.using System.Drawing;
06.using System.Linq;
07.using System.Text;
08.using System.Windows.Forms;
09. 
10.namespace WinFormsCheckBoxDemo
11.{
12.    public partial class Form1 : Form
13.    {
14. 
15.        public Form1()
16.        {
17.            InitializeComponent();
18.        }
19. 
20.        private void chkBold_CheckedChanged(object sender, EventArgs e)
21.        {
22.            ApplyFontStyle();
23.        }
24. 
25.        private void chkItalic_CheckedChanged(object sender, EventArgs e)
26.        {
27.            ApplyFontStyle();
28.        }
29. 
30.        private void chkUnderline_CheckedChanged(object sender, EventArgs e)
31.        {
32.            ApplyFontStyle();
33.        }
34. 
35. 
36.        private void ApplyFontStyle()
37.        {
38.            FontStyle fs = FontStyle.Regular;
39. 
40.            if (chkBold.Checked == true)
41.            {
42.                fs = FontStyle.Bold;
43.            }
44. 
45.            if (chkItalic.Checked)
46.            {
47.                fs = fs | FontStyle.Italic;
48.            }
49. 
50.            if (chkUnderline.Checked)
51.            {
52.                fs = fs | FontStyle.Underline;
53.            }
54. 
55.            this.textBox1.Font = new Font(this.textBox1.Font.FontFamily,
56.                this.textBox1.Font.Size, fs);
57. 
58.        }
59. 
60.    }
61.}

Join the .NET Code Central Community and join the discussion!
Signing-up is FREE and quick. Do it now, we want to hear your opinion
0

Rated 0 from 0 votes ( login  to rate)
DotnetKicks DotnetKicksDe DotNetShoutout

Attachments / Source Code
You need to Login or Join for FREE to download the following