System.Windows.Forms.Form.CancelButton Property

Gets or sets the button control that is clicked when the user presses the ESC key.

Syntax

[System.ComponentModel.DefaultValue(null)]
public IButtonControl CancelButton { set; get; }

Value

Documentation for this section has not yet been entered.

Remarks

The cancel button for a form is the button control that is clicked whenever the user presses the ESC key. The button assigned to this property must be an System.Windows.Forms.IButtonControl that is on the current form or located within a container on the current form.

This property allows you to designate a default action to occur when the user presses the ESC key in your application. You can use this property to allow the user to quickly navigate a simple form by allowing them to simply press the ESC key to close a window without committing changes instead of manually clicking the cancel button with their mouse.

Form.CancelButton may not work if another control on the form intercepts the ESC key. For example, if you have a System.Windows.Forms.ComboBox open on your form, ESC will close the System.Windows.Forms.ComboBox instead of closing the Form.

The System.Windows.Forms.IButtonControl object assigned to Form.CancelButton must be visible on the form, or else pressing the ESC key will have no effect.

Requirements

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