CheckBox with Label : CheckBox « GUI Windows Form « C# / C Sharp






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 i = 0; i < 4; i++)
          {
               CheckBox chkbox = new CheckBox();
               chkbox.Parent = this;
               chkbox.Text = astrText[i];
               chkbox.Location = new Point(2 * cxText, (4 + 3 * i) * cyText / 2);
               chkbox.Size = new Size(12 * cxText, cyText);
               chkbox.CheckedChanged += new EventHandler(CheckBoxOnCheckedChanged);
          }
     }
     void CheckBoxOnCheckedChanged(object obj, EventArgs ea)
     {
          for (int i = 0; i < 4; i++)
               if (((CheckBox) Controls[i + 1]).Checked)
                    fs |= afs[i];
   
          label.Font = new Font(label.Font, fs);
     }
}

 








Related examples in the same category

1.CheckBox Image
2.Subclass CheckBox
3.CheckedChanged Event
4.Is CheckBox checkedIs CheckBox checked
5.CheckBox click (Selected/Unselected) eventCheckBox click (Selected/Unselected) event
6.CheckButton on a FormCheckButton on a Form
7.CheckBox StyleCheckBox Style