2 // Permission is hereby granted, free of charge, to any person obtaining
3 // a copy of this software and associated documentation files (the
4 // "Software"), to deal in the Software without restriction, including
5 // without limitation the rights to use, copy, modify, merge, publish,
6 // distribute, sublicense, and/or sell copies of the Software, and to
7 // permit persons to whom the Software is furnished to do so, subject to
8 // the following conditions:
10 // The above copyright notice and this permission notice shall be
11 // included in all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 // Copyright (c) 2004-2005 Novell, Inc.
24 // Peter Bartok pbartok@novell.com
27 using System.ComponentModel;
29 using System.Drawing.Text;
30 using System.Runtime.InteropServices;
32 namespace System.Windows.Forms {
34 [ClassInterface (ClassInterfaceType.AutoDispatch)]
36 [Designer ("System.Windows.Forms.Design.ButtonBaseDesigner, " + Consts.AssemblySystem_Design,
37 "System.ComponentModel.Design.IDesigner")]
39 public class Button : ButtonBase, IButtonControl {
40 #region Local variables
41 DialogResult dialog_result;
42 #endregion // Local variables
44 #region Public Constructors
46 dialog_result = DialogResult.None;
47 SetStyle(ControlStyles.StandardDoubleClick, false);
49 #endregion // Public Constructors
51 #region Internal methods
52 internal override void HaveDoubleClick() {
53 EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
55 eh (this, EventArgs.Empty);
57 #endregion // Internal methods
59 #region Public Instance Properties
60 [DefaultValue(DialogResult.None)]
61 public virtual DialogResult DialogResult { // IButtonControl
66 dialog_result = value;
69 #endregion // Public Instance Properties
71 #region Protected Instance Properties
72 protected override CreateParams CreateParams {
74 return base.CreateParams;
77 #endregion // Protected Instance Properties
79 #region Public Instance Methods
80 public virtual void NotifyDefault(bool value) { // IButtonControl
81 this.IsDefault = value;
84 public void PerformClick() { // IButtonControl
86 OnClick(EventArgs.Empty);
89 public override string ToString() {
90 return base.ToString() + ", Text: " + this.Text;
92 #endregion // Public Instance Methods
94 #region Protected Instance Methods
95 protected override void OnClick(EventArgs e) {
96 if (dialog_result != DialogResult.None) {
97 Form p = Parent as Form;
100 p.DialogResult = dialog_result;
106 protected override void OnMouseUp(MouseEventArgs e) {
110 protected override bool ProcessMnemonic(char charCode) {
111 if (IsMnemonic(charCode, Text) == true) {
116 return base.ProcessMnemonic(charCode);
119 protected override void WndProc(ref Message m) {
120 base.WndProc (ref m);
122 #endregion // Protected Instance Methods
125 static object DoubleClickEvent = new object ();
127 // XXX this and HaveDoubleClick above need to be
128 // looked at.. it's far more likely that this just
129 // uses base.DoubleClick, and HaveDoubleClick goes
130 // away in favor of calls to OnDoubleClick.
132 [EditorBrowsable (EditorBrowsableState.Advanced)]
133 public new event EventHandler DoubleClick {
134 add { Events.AddHandler (DoubleClickEvent, value); }
135 remove { Events.RemoveHandler (DoubleClickEvent, value); }
139 protected override void OnMouseEnter (EventArgs e)
141 base.OnMouseEnter (e);
144 protected override void OnMouseLeave (EventArgs e)
146 base.OnMouseLeave (e);
149 protected override void OnTextChanged (EventArgs e)
151 base.OnTextChanged (e);