1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004 Novell, Inc.
23 // Dennis Hayes dennish@raytek.com
24 // Peter Bartok pbartok@novell.com
30 using System.ComponentModel;
33 namespace System.Windows.Forms {
34 [DefaultProperty("Checked")]
35 [DefaultEvent("CheckedChanged")]
36 public class CheckBox : ButtonBase {
37 #region Local Variables
38 internal Appearance appearance;
39 internal bool auto_check;
40 internal ContentAlignment check_alignment;
41 internal CheckState check_state;
42 internal bool three_state;
43 #endregion // Local Variables
46 #region Public Constructors
48 appearance = Appearance.Normal;
50 check_alignment = ContentAlignment.MiddleLeft;
51 text_alignment = ContentAlignment.MiddleLeft;
53 #endregion // Public Constructors
55 #region Internal Methods
56 internal override void Draw (PaintEventArgs pe) {
58 ThemeEngine.Current.DrawCheckBox (this.DeviceContext, this.ClientRectangle, this);
63 internal override void HaveDoubleClick() {
64 if (DoubleClick != null) DoubleClick(this, EventArgs.Empty);
66 #endregion // Internal Methods
68 #region Public Instance Properties
69 [DefaultValue(Appearance.Normal)]
71 public Appearance Appearance {
77 if (value != appearance) {
79 if (AppearanceChanged != null) {
80 AppearanceChanged(this, EventArgs.Empty);
88 public bool AutoCheck {
100 [DefaultValue(ContentAlignment.MiddleLeft)]
101 public ContentAlignment CheckAlign {
103 return check_alignment;
107 if (value != check_alignment) {
108 check_alignment = value;
116 [RefreshProperties(RefreshProperties.All)]
117 [DefaultValue(false)]
118 public bool Checked {
120 if (check_state != CheckState.Unchecked) {
127 if (value && (check_state != CheckState.Checked)) {
128 check_state = CheckState.Checked;
130 OnCheckedChanged(EventArgs.Empty);
131 } else if (!value && (check_state != CheckState.Unchecked)) {
132 check_state = CheckState.Unchecked;
134 OnCheckedChanged(EventArgs.Empty);
139 [DefaultValue(CheckState.Unchecked)]
140 [RefreshProperties(RefreshProperties.All)]
142 public CheckState CheckState {
148 if (value != check_state) {
149 bool was_checked = (check_state != CheckState.Unchecked);
153 if (was_checked != (check_state != CheckState.Unchecked)) {
154 OnCheckedChanged(EventArgs.Empty);
157 OnCheckStateChanged(EventArgs.Empty);
163 [DefaultValue(ContentAlignment.MiddleLeft)]
165 public override ContentAlignment TextAlign {
167 return text_alignment;
171 if (value != text_alignment) {
172 text_alignment = value;
179 [DefaultValue(false)]
180 public bool ThreeState {
189 #endregion // Public Instance Properties
191 #region Protected Instance Properties
192 protected override CreateParams CreateParams {
194 return base.CreateParams;
198 protected override Size DefaultSize {
200 return new Size(104, 24);
203 #endregion // Protected Instance Properties
205 #region Public Instance Methods
206 public override string ToString() {
207 return base.ToString() + ", CheckState: " + (int)check_state;
209 #endregion // Public Instance Methods
211 #region Protected Instance Methods
212 protected override AccessibleObject CreateAccessibilityInstance() {
213 return base.CreateAccessibilityInstance ();
216 protected virtual void OnAppearanceChanged(EventArgs e) {
217 if (AppearanceChanged != null) {
218 AppearanceChanged(this, e);
222 protected virtual void OnCheckedChanged(EventArgs e) {
223 if (CheckedChanged != null) {
224 CheckedChanged(this, e);
228 protected virtual void OnCheckStateChanged(EventArgs e) {
229 if (CheckStateChanged != null) {
230 CheckStateChanged(this, e);
234 protected override void OnClick(EventArgs e) {
236 switch(check_state) {
237 case CheckState.Unchecked: {
239 CheckState = CheckState.Indeterminate;
241 CheckState = CheckState.Checked;
246 case CheckState.Indeterminate: {
247 CheckState = CheckState.Checked;
251 case CheckState.Checked: {
252 CheckState = CheckState.Unchecked;
259 protected override void OnHandleCreated(EventArgs e) {
260 base.OnHandleCreated (e);
263 protected override void OnMouseUp(MouseEventArgs e) {
267 protected override bool ProcessMnemonic(char charCode) {
268 return base.ProcessMnemonic (charCode);
270 #endregion // Protected Instance Methods
273 public event EventHandler AppearanceChanged;
274 public event EventHandler CheckedChanged;
275 public event EventHandler CheckStateChanged;
280 [EditorBrowsable (EditorBrowsableState.Never)]
281 public event EventHandler DoubleClick;