Previous Topic

Next Topic

Inhoudsopgave

Book Index

TButton Control

TButton

Description

Provides a push button control.

Remarks

Use TButton to put a standard push button on a form. TButton introduces several properties to control its behavior in a dialog box setting. Users choose button controls to initiate actions.

TButton Properties

Property Property Cancel: Boolean (R/W)

Determines whether the button's OnClick event handler executes when the Escape key is pressed. If Cancel is true, the button's OnClick event handler executes when the user presses Esc. Although an application can have more than one Cancel button, the form calls the OnClick event handler only for the first visible button in the tab order.

Property Property Default: Boolean (R/W)

Determines whether the button's OnClick event handler executes when the Enter key is pressed. If Default is true, the button's OnClick event handler executes when the user presses Enter. Although an application can have more than one Default button, the form calls the OnClick event handler only for the first visible button in the tab order. Moreover, any button that has focus becomes the Default button temporarily; hence, if the user selects another button before pressing Enter, the selected button's OnClick event handler executes instead.

Property Property ModalResult: Enumerated (mrNone, mrOk, mrCancel, mrAbort, mrRetry, mrIgnore, mrYes, mrNo, mrAll, mrNoToAll, mrYesToAll) Boolean (R/W)

Determines whether and how the button closes its (modal) parent form. Setting the TButton component's ModalResult property is an easy way to make clicking the button close a modal form. When a button is clicked, the ModalResult property of its parent form is set to the same value as the button's ModalResult property. For example, if a dialog box has OK and Cancel buttons, their ModalResult properties could be set at design time to mrOk and mrCancel, respectively. At runtime, clicking the OK button then changes the dialog's ModalResult property to mrOk, and clicking the Cancel button changes the dialog's ModalResult property to mrCancel. Unless further processing is required, no OnClick event handlers are required for the buttons.

Property Property Caption: String (R/W)

Specifies the caption that appears on the button. Use Caption to specify the text string that appears on the button. To underline a character in a Caption that appears on the button, include an ampersand (&) before the character. This type of character is called an accelerator character. The user can then select the button by pressing Alt while typing the underlined character. To display an ampersand character in the caption, use two ampersands (&&).

TButton Methods

Method Method Click

Simulates a mouse click, as if the user had clicked the button. Calling Click assigns the value of the button's ModalResult property to the ModalResult property of its parent form, and then generates an OnClick event.