new CheckBox() : CheckBox « System.Windows.Forms « C# / C Sharp by API






new CheckBox()

 

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.extends CheckBox
2.CheckBox.CheckAlign
3.CheckBox.Checked
4.CheckBox.CheckedChanged
5.CheckBox.ThreeState