System.Windows.Forms.Button Class

Represents a Windows button control.

See Also: Button Members

Syntax

[System.ComponentModel.Designer("System.Windows.Forms.Design.ButtonBaseDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.IDesigner")]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
public class Button : ButtonBase, IButtonControl

Remarks

A System.Windows.Forms.Button can be clicked by using the mouse, ENTER key, or SPACEBAR if the button has focus.

Set the Form.AcceptButton or Form.CancelButton property of a System.Windows.Forms.Form to allow users to click a button by pressing the ENTER or ESC keys even if the button does not have focus. This gives the form the behavior of a dialog box.

When you display a form using the Form.ShowDialog method, you can use the Button.DialogResult property of a button to specify the return value of Form.ShowDialog.

You can change the button's appearance. For example, to make it appear flat for a Web look, set the ButtonBase.FlatStyle property to FlatStyle.Flat. The ButtonBase.FlatStyle property can also be set to FlatStyle.Popup, which appears flat until the mouse pointer passes over the button; then the button takes on the standard Windows button appearance.

Note:

If the control that has focus accepts and processes the ENTER key press, the System.Windows.Forms.Button does not process it. For example, if a multiline System.Windows.Forms.TextBox or another button has focus, that control processes the ENTER key press instead of the accept button.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0