using System;
using System.Drawing;
using System.ComponentModel;
+using System.Windows.Forms.Design;
namespace System.Windows.Forms
{
+ [ToolStripItemDesignerAvailability (ToolStripItemDesignerAvailability.ToolStrip)]
public class ToolStripButton : ToolStripItem
{
private CheckState checked_state;
#region Public Constructors
public ToolStripButton ()
- : this (String.Empty, null, null, String.Empty)
+ : this (null, null, null, String.Empty)
{
}
public ToolStripButton (Image image)
- : this (String.Empty, image, null, String.Empty)
+ : this (null, image, null, String.Empty)
{
}
#endregion
#region Public Properties
- [MonoTODO ("Need 2.0 ToolTip to implement tool tips.")]
[DefaultValue (true)]
- public bool AutoToolTip {
+ public new bool AutoToolTip {
get { return base.AutoToolTip; }
set { base.AutoToolTip = value; }
}
if (this.checked_state != (value ? CheckState.Checked : CheckState.Unchecked)) {
this.checked_state = value ? CheckState.Checked : CheckState.Unchecked;
this.OnCheckedChanged (EventArgs.Empty);
+ this.OnCheckStateChanged (EventArgs.Empty);
this.Invalidate ();
}
}
public CheckState CheckState {
get { return this.checked_state; }
set {
- if (!Enum.IsDefined (typeof (CheckState), value))
- throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for CheckState", value));
+ if (this.checked_state != value) {
+ if (!Enum.IsDefined (typeof (CheckState), value))
+ throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for CheckState", value));
- this.checked_state = value;
- OnCheckStateChanged (EventArgs.Empty);
- this.Invalidate ();
+ this.checked_state = value;
+ this.OnCheckedChanged (EventArgs.Empty);
+ this.OnCheckStateChanged (EventArgs.Empty);
+ this.Invalidate ();
+ }
}
}
#endregion
#region Public Methods
public override Size GetPreferredSize (Size constrainingSize)
{
- return base.GetPreferredSize (constrainingSize);
+ Size retval = base.GetPreferredSize (constrainingSize);
+
+ if (retval.Width < 23)
+ retval.Width = 23;
+
+ return retval;
}
#endregion
#region Protected Methods
+ [EditorBrowsable (EditorBrowsableState.Advanced)]
protected override AccessibleObject CreateAccessibilityInstance ()
{
ToolStripItemAccessibleObject ao = new ToolStripItemAccessibleObject (this);
protected virtual void OnCheckedChanged (EventArgs e)
{
- if (CheckedChanged != null) CheckedChanged (this, e);
+ EventHandler eh = (EventHandler)(Events [CheckedChangedEvent]);
+ if (eh != null)
+ eh (this, e);
}
protected virtual void OnCheckStateChanged (EventArgs e)
{
- if (CheckStateChanged != null) CheckStateChanged (this, e);
+ EventHandler eh = (EventHandler)(Events [CheckStateChangedEvent]);
+ if (eh != null)
+ eh (this, e);
}
protected override void OnClick (EventArgs e)
#endregion
#region Public Events
- public event EventHandler CheckedChanged;
- public event EventHandler CheckStateChanged;
+ static object CheckedChangedEvent = new object ();
+ static object CheckStateChangedEvent = new object ();
+
+ public event EventHandler CheckedChanged {
+ add { Events.AddHandler (CheckedChangedEvent, value); }
+ remove { Events.RemoveHandler (CheckedChangedEvent, value); }
+ }
+
+ public event EventHandler CheckStateChanged {
+ add { Events.AddHandler (CheckStateChangedEvent, value); }
+ remove { Events.RemoveHandler (CheckStateChangedEvent, value); }
+ }
#endregion
}
}