Bagikan melalui


Button Control Overview (Windows Forms)

The Windows Forms Button control allows the user to click it to perform an action. When the button is clicked, it looks as if it is being pushed in and released. Whenever the user clicks a button, the Click event handler is invoked. You place code in the Click event handler to perform any action you choose.

The text displayed on the button is contained in the Text property. If your text exceeds the width of the button, it will wrap to the next line. However, it will be clipped if the control cannot accommodate its overall height. For more information, see How to: Set the Text Displayed by a Windows Forms Control. The Text property can contain an access key, which allows a user to "click" the control by pressing the ALT key with the access key. For details, see How to: Create Access Keys for Windows Forms Controls. The appearance of the text is controlled by the Font property and the TextAlign property.

The Button control can also display images using the Image and ImageList properties. For more information, see How to: Set the Image Displayed by a Windows Forms Control.

See Also

Tasks

How to: Respond to Windows Forms Button Clicks

How to: Designate a Windows Forms Button as the Accept Button Using the Designer

How to: Designate a Windows Forms Button as the Cancel Button Using the Designer

Reference

Button

Concepts

Ways to Select a Windows Forms Button Control

Other Resources

Button Control (Windows Forms)