Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


CSharp Programming

CSharp > Code Examples

CheckBox with Label

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
CheckBox with Label using System; using System.Drawing; using System.Windows.Forms; class CheckBoxWithLabel: Form { Label label; FontStyle fs = 0; FontStyle[] afs = { FontStyle.Bold,FontStyle.Italic, FontStyle.Underline, FontStyle.Strikeout }; public static void Main() { Application.Run(new CheckBoxWithLabel()); } public CheckBoxWithLabel() { int cyText = Font.Height; int cxText = cyText / 2; string[] astrText = {"Bold", "Italic", "Underline", "Strikeout"}; label = new Label(); label.Parent = this; label.Text = "Sample Text"; label.AutoSize = true; for (int j = 0; j < 4; j++) { CheckBox chkbox = new CheckBox(); chkbox.Parent = this; chkbox.Text = astrText[j]; chkbox.Location = new Point(2 * cxText, (4 + 3 * j) * cyText / 2); chkbox.Size = new Size(12 * cxText, cyText); chkbox.CheckedChanged += new EventHandler(CheckBoxOnCheckedChanged); } } void CheckBoxOnCheckedChanged(object obj, EventArgs ea) { for (int j = 0; j < 4; j++) if (((CheckBox) Controls[j + 1]).Checked) fs |= afs[j]; label.Font = new Font(label.Font, fs); } }