Sylloge
A C# helper library
code/Controls/CheckBox.cs
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00018 using System;
00019 using System.Collections.Generic;
00020 using System.ComponentModel;
00021 using System.Drawing;
00022 using System.Data;
00023 using System.Text;
00024 using System.Windows.Forms;
00025 
00026 namespace Sylloge.Controls
00027 {
00031     public partial class CheckBox : UserControl
00032     {
00033         #region Events
00034 
00035         public delegate void DelegateCheckedChanged(Sylloge.Controls.CheckBox sender, System.EventArgs e);
00036         public delegate void DelegateLinkLabelClicked(System.Object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e);
00037         public delegate void DelegateMouseClick(System.Object sender, System.EventArgs e);
00041         public event DelegateCheckedChanged CheckedChanged;
00045         public new event DelegateMouseClick Click;
00049         public event DelegateLinkLabelClicked LinkLabelClicked;
00050 
00051         private void OnCheckedChanged(System.EventArgs e)
00052         {
00053             if (this.CheckedChanged != null) { this.CheckedChanged(this, e); }
00054         }
00055 
00056         private void OnUserClick(System.EventArgs e)
00057         {
00058             if (this.Click != null) { this.Click(this, e); }
00059         }
00060 
00061         private void OnLinkLabelClicked(System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
00062         {
00063             if (this.LinkLabelClicked != null) { this.LinkLabelClicked(this, e); }
00064         }
00065 
00066         #endregion
00067 
00068         #region Local Attributes
00069 
00070         public enum CheckBoxType
00071         {
00072             CheckBox,
00073             ArrowBox
00074         }
00075 
00076         private bool _Checked { get; set; }
00077         private bool _IsLinkLabel { get; set; }
00078         private string _Label { get; set; }
00079         private string _ToolTip { get; set; }
00080         private CheckBoxType _Type { get; set; }
00081 
00082         #endregion
00083 
00084         #region Class Methods and Properties
00085 
00086         public CheckBox()
00087         {
00088             this.InitializeComponent();
00089             this._Checked = false;
00090             this._ToolTip = string.Empty;
00091             this._Label = "Check Box";
00092             this.IsLinkLabel = false;
00093         }
00094 
00099         public bool Checked
00100         {
00101             get
00102             {
00103                 return this._Checked;
00104             }
00105             set
00106             {
00107                 this._Checked = value;
00108                 this.c_CheckBoxMain.Checked = value;
00109             }
00110         }
00111 
00115         public bool IsLinkLabel
00116         {
00117             get
00118             {
00119                 return this._IsLinkLabel;
00120             }
00121             set
00122             {
00123                 this._IsLinkLabel = value;
00124                 if (value) {
00125                     this.c_LinkLabelLink.Visible = true;
00126                     this.c_LinkLabelLink.BringToFront();
00127                 } else {
00128                     this.c_LinkLabelLink.Visible = false;
00129                     this.c_LinkLabelLink.SendToBack();
00130                 }
00131             }
00132         }
00133 
00137         public string Label
00138         {
00139             get
00140             {
00141                 return this.Text;
00142             }
00143             set
00144             {
00145                 this.Text = value;
00146             }
00147         }
00148 
00152         private void SetImage()
00153         {
00154             if (this.c_CheckBoxMain.Checked) {
00155                 switch (this.Type) {
00156                     case CheckBoxType.ArrowBox:
00157                         this.c_PictureBoxMain.Image = Properties.Resources.ArrowsUp;
00158                         break;
00159                     case CheckBoxType.CheckBox:
00160                         this.c_PictureBoxMain.Image = Properties.Resources.CheckBoxCheck;
00161                         break;
00162                 }
00163             } else {
00164                 switch (this.Type) {
00165                     case CheckBoxType.ArrowBox:
00166                         this.c_PictureBoxMain.Image = Properties.Resources.ArrowsDown;
00167                         break;
00168                     case CheckBoxType.CheckBox:
00169                         this.c_PictureBoxMain.Image = Properties.Resources.CheckBoxMinus;
00170                         break;
00171                 }
00172             }
00173         }
00174 
00178         public new string Text
00179         {
00180             get
00181             {
00182                 return this._Label;
00183             }
00184             set
00185             {
00186                 this._Label = value;
00187                 this.c_CheckBoxMain.Text = value;
00188                 this.c_LinkLabelLink.Text = value;
00189             }
00190         }
00191 
00195         public string ToolTip
00196         {
00197             get
00198             {
00199                 return this._ToolTip;
00200             }
00201             set
00202             {
00203                 this._ToolTip = value;
00204                 this.c_ToolTip.SetToolTip(this.c_CheckBoxMain, value);
00205                 this.c_ToolTip.SetToolTip(this.c_PictureBoxMain, value);
00206             }
00207         }
00208 
00212         public CheckBoxType Type
00213         {
00214             get
00215             {
00216                 return this._Type;
00217             }
00218             set
00219             {
00220                 this._Type = value;
00221                 this.SetImage();
00222             }
00223         }
00224 
00225         #endregion
00226 
00227         #region Control Event Handlers
00228 
00229         private void c_PictureBoxMain_Click(object sender, System.EventArgs e)
00230         {
00231             this.c_CheckBoxMain.Checked = !this.c_CheckBoxMain.Checked;
00232             this.OnUserClick(e);
00233         }
00234 
00235         private void c_CheckBoxMain_Click(object sender, System.EventArgs e)
00236         {
00237             this.OnUserClick(e);
00238         }
00239 
00240         private void c_CheckBoxMain_CheckedChanged(object sender, System.EventArgs e)
00241         {
00242             this.SetImage();
00243             this._Checked = this.c_CheckBoxMain.Checked;
00244             if (!this.DesignMode) {
00245                 this.OnCheckedChanged(e);
00246             }
00247         }
00248 
00249         private void c_LinkLabelLink_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
00250         {
00251             this.OnLinkLabelClicked(e);
00252         }
00253 
00254         #endregion
00255     }
00256 }
 All Classes Namespaces Files Functions Variables Enumerations Properties Events