CheckedChanged Event

using System;
using System.Drawing;
using System.Windows.Forms;

class RadioButtons: Form
{
bool bFillEllipse;
Color colorEllipse;

static void Main()
{
Application.Run(new RadioButtons());
}
RadioButtons()
{
ResizeRedraw = true;
string[] astrColor = { “Black”, “Blue”, “Green”, “Cyan”};

GroupBox grpbox = new GroupBox();
grpbox.Parent = this;
grpbox.Text = “Color”;
grpbox.Location = new Point(Font.Height / 2, Font.Height / 2);
grpbox.Size = new Size(9 * Font.Height, (3 * astrColor.Length + 4) * Font.Height / 2);

for (int i = 0; i < astrColor.Length; i++) { RadioButton radiobtn = new RadioButton(); radiobtn.Parent = grpbox; radiobtn.Text = astrColor[i]; radiobtn.Location = new Point(Font.Height,3 * (i + 1) * Font.Height / 2); radiobtn.Size = new Size(7 * Font.Height,3 * Font.Height / 2); radiobtn.CheckedChanged += new EventHandler(RadioButtonOnCheckedChanged); radiobtn.Checked = true; } CheckBox chkbox = new CheckBox(); chkbox.Parent = this; chkbox.Text = "Fill Ellipse"; chkbox.Location = new Point(Font.Height, 3 * (astrColor.Length + 2) * Font.Height / 2); chkbox.Size = new Size(Font.Height * 7, 3 * Font.Height / 2); chkbox.CheckedChanged += new EventHandler(CheckBoxOnCheckedChanged); } void RadioButtonOnCheckedChanged(object obj, EventArgs ea) { RadioButton radiobtn = (RadioButton) obj; if(radiobtn.Checked) { colorEllipse = Color.FromName(radiobtn.Text); Invalidate(false); } } void CheckBoxOnCheckedChanged(object obj, EventArgs ea) { bFillEllipse = ((CheckBox)obj).Checked; Invalidate(false); } protected override void OnPaint(PaintEventArgs pea) { Graphics grfx = pea.Graphics; Rectangle rect = new Rectangle(10 * Font.Height, 0, ClientSize.Width - 10 * Font.Height - 1, ClientSize.Height - 1); if(bFillEllipse) grfx.FillEllipse(new SolidBrush(colorEllipse), rect); else grfx.DrawEllipse(new Pen(colorEllipse), rect); } } [/csharp]

Subclass CheckBox

using System;
using System.Drawing;
using System.Windows.Forms;

class CustomCheckBox: Form
{
public static void Main()
{
Application.Run(new CustomCheckBox());
}
public CustomCheckBox()
{
int cyText = Font.Height;
int cxText = cyText / 2;
FontStyle[] afs = { FontStyle.Bold, FontStyle.Italic,
FontStyle.Underline, FontStyle.Strikeout };

Label label = new Label();
label.Parent = this;
label.Text = “Sample Text”;
label.AutoSize = true;

for (int i = 0; i < 4; i++) { FontStyleCheckBox chkbox = new FontStyleCheckBox(); chkbox.Parent = this; chkbox.Text = afs[i].ToString(); chkbox.fontstyle = afs[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) { FontStyle fs = 0; Label label = null; for (int i = 0; i < Controls.Count; i++) { Control ctrl = Controls[i]; if (ctrl.GetType() == typeof(Label)) label = (Label) ctrl; else if (ctrl.GetType() == typeof(FontStyleCheckBox)) if (((FontStyleCheckBox) ctrl).Checked) fs |= ((FontStyleCheckBox) ctrl).fontstyle; } label.Font = new Font(label.Font, fs); } } class FontStyleCheckBox: CheckBox { public FontStyle fontstyle; } [/csharp]

CheckBox Image

   
 
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class Form1 : System.Windows.Forms.Form {
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.CheckBox chk_option1;
    private System.Windows.Forms.CheckBox chk_option2;
    private System.Windows.Forms.CheckBox chk_option3;
    private System.Windows.Forms.CheckBox chk_option4;
    private System.Windows.Forms.Button button1;

    public Form1() {
        this.chk_option1 = new System.Windows.Forms.CheckBox();
        this.label1 = new System.Windows.Forms.Label();
        this.chk_option2 = new System.Windows.Forms.CheckBox();
        this.chk_option3 = new System.Windows.Forms.CheckBox();
        this.chk_option4 = new System.Windows.Forms.CheckBox();
        this.groupBox1 = new System.Windows.Forms.GroupBox();
        this.button1 = new System.Windows.Forms.Button();
        this.groupBox1.SuspendLayout();
        this.SuspendLayout();
        // 
        // chk_option1
        // 
        this.chk_option1.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
        this.chk_option1.Location = new System.Drawing.Point(40, 24);
        this.chk_option1.Name = "chk_option1";
        this.chk_option1.Size = new System.Drawing.Size(192, 24);
        this.chk_option1.TabIndex = 0;
        this.chk_option1.Text = "Windows 2000 / Windows XP";
        this.chk_option1.ThreeState = true;
        // 
        // label1
        // 
        this.label1.Location = new System.Drawing.Point(16, 24);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(296, 16);
        this.label1.TabIndex = 1;
        this.label1.Text = "The following products are developed by Microsoft Corp.";
        // 
        // chk_option2
        // 
        this.chk_option2.Location = new System.Drawing.Point(40, 56);
        this.chk_option2.Name = "chk_option2";
        this.chk_option2.Size = new System.Drawing.Size(192, 24);
        this.chk_option2.TabIndex = 0;
        this.chk_option2.Text = "JAVA";
        // 
        // chk_option3
        // 
        this.chk_option3.Appearance = System.Windows.Forms.Appearance.Button;
        this.chk_option3.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
        this.chk_option3.Location = new System.Drawing.Point(40, 88);
        this.chk_option3.Name = "chk_option3";
        this.chk_option3.Size = new System.Drawing.Size(192, 24);
        this.chk_option3.TabIndex = 0;
        this.chk_option3.Text = "Visual C# and .NET";
        // 
        // chk_option4
        // 
        this.chk_option4.Appearance = System.Windows.Forms.Appearance.Button;
        this.chk_option4.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
        this.chk_option4.Location = new System.Drawing.Point(40, 120);
        this.chk_option4.Name = "chk_option4";
        this.chk_option4.Size = new System.Drawing.Size(192, 24);
        this.chk_option4.TabIndex = 0;
        this.chk_option4.Text = "Oracle Database";
        // 
        // groupBox1
        // 
        this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
                                          this.chk_option2,
                                          this.chk_option4,
                                          this.chk_option3,
                                          this.chk_option1});
        this.groupBox1.Location = new System.Drawing.Point(16, 56);
        this.groupBox1.Name = "groupBox1";
        this.groupBox1.Size = new System.Drawing.Size(280, 152);
        this.groupBox1.TabIndex = 2;
        this.groupBox1.TabStop = false;
        this.groupBox1.Text = "Select All Correct Options";
        // 
        // button1
        // 
        this.button1.Location = new System.Drawing.Point(16, 216);
        this.button1.Name = "button1";
        this.button1.TabIndex = 3;
        this.button1.Text = "Done ";
        this.button1.Click += new System.EventHandler(this.button1_Click);
        // 
        // Form1
        // 
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
        this.ClientSize = new System.Drawing.Size(328, 253);
        this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.button1,
                                      this.groupBox1,
                                      this.label1});
        this.Name = "Form1";
        this.Text = "Check Boxes";
        this.Load += new System.EventHandler(this.Form1_Load);
        this.groupBox1.ResumeLayout(false);
        this.ResumeLayout(false);

    }


    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() {
        Application.Run(new Form1());
    }

    private void Form1_Load(object sender, System.EventArgs e) {
        Image imga = Image.FromFile("A.ICO");
        chk_option3.Image = imga;
        chk_option3.ImageAlign = ContentAlignment.MiddleRight;
        chk_option3.BackColor = Color.LightBlue;
        imga = Image.FromFile("B.ICO");
        chk_option4.Image = imga;
        chk_option4.ImageAlign = ContentAlignment.MiddleCenter;
        chk_option4.BackColor = Color.LightBlue;
    }

    private void button1_Click(object sender, System.EventArgs e) {
        string str_opt_selected = "Options Selected are ..
";
        if (chk_option1.Checked)
            str_opt_selected = str_opt_selected + chk_option1.Text + "
";
        if (chk_option2.Checked)
            str_opt_selected = str_opt_selected + chk_option2.Text + "
";
        if (chk_option3.Checked)
            str_opt_selected = str_opt_selected + chk_option3.Text + "
";
        if (chk_option4.Checked)
            str_opt_selected = str_opt_selected + chk_option4.Text + "
";

        MessageBox.Show(str_opt_selected, "Checked Options");

    }
}

    


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); } } [/csharp]

Get selected checkbox list items

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class Form1 : System.Windows.Forms.Form {
private System.Windows.Forms.CheckedListBox chkListPossibleValues;
private System.Windows.Forms.ListBox lstSelected;
private System.Windows.Forms.Button btnMove;
private System.ComponentModel.Container components=null;

public Form1() {
InitializeComponent();
this.chkListPossibleValues.Items.Add(“Ten”);
}

private void InitializeComponent() {
this.lstSelected = new System.Windows.Forms.ListBox();
this.btnMove = new System.Windows.Forms.Button();
this.chkListPossibleValues = new System.Windows.Forms.CheckedListBox();
this.SuspendLayout();

this.lstSelected.Location = new System.Drawing.Point(232, 8);
this.lstSelected.Name = “lstSelected”;
this.lstSelected.Size = new System.Drawing.Size(136, 186);
this.lstSelected.TabIndex = 1;

this.btnMove.Location = new System.Drawing.Point(152, 80);
this.btnMove.Name = “btnMove”;
this.btnMove.TabIndex = 3;
this.btnMove.Text = “Move”;
this.btnMove.Click += new System.EventHandler(this.btnMove_Click);

this.chkListPossibleValues.CheckOnClick = true;
this.chkListPossibleValues.Items.AddRange(new object[] {“One”, “Two”, “Three”,
“Four”, “Five”,”Six”,”Seven”, “Eight”, “Nine”});
this.chkListPossibleValues.Location = new System.Drawing.Point(8, 8);
this.chkListPossibleValues.Name = “chkListPossibleValues”;
this.chkListPossibleValues.Size = new System.Drawing.Size(136, 184);
this.chkListPossibleValues.TabIndex = 0;

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(376, 205);
this.Controls.AddRange(new System.Windows.Forms.Control[] {this.btnMove,
this.lstSelected, this.chkListPossibleValues});
this.Name = “Form1”;
this.Text = “List Boxes”;
this.ResumeLayout(false);

}

static void Main() {
Application.Run(new Form1());
}

private void btnMove_Click(object sender, System.EventArgs e) {
if (this.chkListPossibleValues.CheckedItems.Count > 0) {
this.lstSelected.Items.Clear();
foreach (string item in this.chkListPossibleValues.CheckedItems) {
this.lstSelected.Items.Add(item.ToString());
}
for (int i = 0; i < this.chkListPossibleValues.Items.Count; i++){ this.chkListPossibleValues.SetItemChecked(i, false); } } } } [/csharp]

CheckedListBox Item Check event


   

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

public class Form1 : Form
{
      private System.Windows.Forms.CheckedListBox inputCheckedListBox;
      private System.Windows.Forms.ListBox displayListBox;
    
    public Form1() {
         InitializeComponent();
    }
      private void inputCheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e )
      {
         string item = inputCheckedListBox.SelectedItem.ToString();

         if ( e.NewValue == CheckState.Checked )
            displayListBox.Items.Add( item );
         else
            displayListBox.Items.Remove( item );
      }
      private void InitializeComponent()
      {
         this.inputCheckedListBox = new System.Windows.Forms.CheckedListBox();
         this.displayListBox = new System.Windows.Forms.ListBox();
         this.SuspendLayout();
         // 
         // inputCheckedListBox
         // 
         this.inputCheckedListBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
         this.inputCheckedListBox.FormattingEnabled = true;
         this.inputCheckedListBox.Items.AddRange(new object[] {
            "A",
            "B",
            "C",
            "D",
            "E",
            "F",
            "G",
            "H"});
         this.inputCheckedListBox.Location = new System.Drawing.Point(17, 12);
         this.inputCheckedListBox.Name = "inputCheckedListBox";
         this.inputCheckedListBox.Size = new System.Drawing.Size(202, 188);
         this.inputCheckedListBox.TabIndex = 0;
         this.inputCheckedListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.inputCheckedListBox_ItemCheck);
         // 
         // displayListBox
         // 
         this.displayListBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
         this.displayListBox.FormattingEnabled = true;
         this.displayListBox.ItemHeight = 20;
         this.displayListBox.Location = new System.Drawing.Point(236, 12);
         this.displayListBox.Name = "displayListBox";
         this.displayListBox.Size = new System.Drawing.Size(190, 184);
         this.displayListBox.TabIndex = 1;
         // 
         // CheckedListBoxTestForm
         // 
         this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
         this.ClientSize = new System.Drawing.Size(438, 211);
         this.Controls.Add(this.displayListBox);
         this.Controls.Add(this.inputCheckedListBox);
         this.Name = "CheckedListBoxTestForm";
         this.Text = "CheckedListBoxTest";
         this.ResumeLayout(false);

      }

  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }

}



           
          


Date Time Picker 2


   

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace DateTimePicker
{
    /// <summary>
    /// Summary description for DateTimePicker2.
    /// </summary>
    public class DateTimePicker2 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.DateTimePicker dateTimePicker1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public DateTimePicker2()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
         this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
         this.SuspendLayout();
         // 
         // dateTimePicker1
         // 
         this.dateTimePicker1.Location = new System.Drawing.Point(8, 16);
         this.dateTimePicker1.Name = "dateTimePicker1";
         this.dateTimePicker1.RightToLeft = System.Windows.Forms.RightToLeft.No;
         this.dateTimePicker1.ShowUpDown = true;
         this.dateTimePicker1.TabIndex = 0;
         // 
         // DateTimePicker2
         // 
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(216, 61);
         this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                      this.dateTimePicker1});
         this.Name = "DateTimePicker2";
         this.Text = "DateTimePicker";
         this.Load += new System.EventHandler(this.DateTimePicker2_Load);
         this.ResumeLayout(false);

      }
        #endregion

        private void DateTimePicker2_Load(object sender, System.EventArgs e)
        {
        
        }
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new DateTimePicker2());
        }
        
    }
}