2 // System.Windows.Forms.CheckBox
5 // Joel Basson (jstrike@mweb.co.za)
6 // Alberto Fernandez (infjaf00@yahoo.es)
11 using System
.ComponentModel
;
13 namespace System
.Windows
.Forms
{
16 /// Represents a Windows CheckBox control.
20 public class CheckBox
: ButtonBase
{
22 private bool autocheck
= false;
23 private bool threeState
= false;
24 private CheckState checkState
;
26 public CheckBox () : base (){
31 public Appearance Appearance
{
33 if ( (Widget
as Gtk
.CheckButton
).DrawIndicator
)
34 return Appearance
.Normal
;
35 return Appearance
.Button
;
38 if (!Enum
.IsDefined (typeof(Appearance
), value) )
39 throw new InvalidEnumArgumentException();
40 if (value != Appearance
){
41 if (value == Appearance
.Normal
)
42 (Widget
as Gtk
.CheckButton
).DrawIndicator
= true;
44 (Widget
as Gtk
.CheckButton
).DrawIndicator
= false;
45 OnAppearanceChanged (EventArgs
.Empty
);
49 public bool AutoCheck
{
50 get { return autocheck; }
51 set { autocheck = value; }
54 public ContentAlignment CheckAlign
{
55 get { return ContentAlignment.MiddleLeft; }
57 if (!Enum
.IsDefined (typeof (ContentAlignment
), value)){
58 throw new InvalidEnumArgumentException ("CheckAlign");
63 get { return (this.CheckState != CheckState.Unchecked); }
64 set { this.CheckState = (value) ? CheckState.Checked : CheckState.Unchecked;}
66 public CheckState CheckState
{
67 get{ return checkState; }
69 if (! Enum
.IsDefined ( typeof(CheckState
), value) )
70 throw new InvalidEnumArgumentException();
73 case CheckState
.Indeterminate
:
74 (Widget
as Gtk
.CheckButton
).Inconsistent
= true;
76 case CheckState
.Checked
:
77 (Widget
as Gtk
.CheckButton
).Inconsistent
= false;
78 (Widget
as Gtk
.CheckButton
).Active
= true;
80 case CheckState
.Unchecked
:
81 (Widget
as Gtk
.CheckButton
).Inconsistent
= false;
82 (Widget
as Gtk
.CheckButton
).Active
= false;
88 protected override Size DefaultSize
{
89 get{ return new Size(104, 24);}
91 public bool ThreeState
{
92 get { return threeState; }
93 set { threeState = value; }
95 protected virtual void OnAppearanceChanged( EventArgs e
){
96 if (AppearanceChanged
!= null)
97 AppearanceChanged (this, e
);
99 protected virtual void OnCheckedChanged( EventArgs e
){
100 if (CheckedChanged
!= null)
101 CheckedChanged (this, e
);
103 protected virtual void OnCheckStateChanged(EventArgs e
){
104 if (CheckStateChanged
!= null)
105 CheckStateChanged (this, e
);
107 public override string ToString(){
108 return "System.Windows.Forms.CheckBox, CheckState: " +
109 (int) this.CheckState
;
112 public event EventHandler AppearanceChanged
;
113 public event EventHandler CheckedChanged
;
114 public event EventHandler CheckStateChanged
;
115 public new event EventHandler DoubleClick
;
119 internal override Gtk
.Widget
CreateWidget () {
120 Gtk
.CheckButton cbox
= new Gtk
.CheckButton();
121 cbox
.Add (label
.Widget
);
124 internal override void ConnectEvents(){
125 (Widget
as Gtk
.CheckButton
).Toggled
+= new EventHandler (GtkToggled
);
129 private bool started
= false;
130 private void GtkToggled (object o
, EventArgs e
){
135 if (this.CheckState
== CheckState
.Indeterminate
){
136 this.CheckState
= CheckState
.Unchecked
;
138 OnCheckStateChanged(e
);
140 else if ((this.CheckState
== CheckState
.Checked
) && (this.ThreeState
)) {
141 this.CheckState
= CheckState
.Indeterminate
;
142 OnCheckStateChanged (e
);
145 this.Checked
= !this.Checked
;
147 OnCheckStateChanged(e
);
152 this.CheckState
= checkState
;