[Overview][Constants][Types][Classes][Procedures and functions][Index] | Reference for unit 'StdCtrls' (#lcl)

# TCustomButton

[Properties (by Name)] [Methods (by Name)] [Events (by Name)]

The base class for a push button control.

## Declaration

Source position: stdctrls.pp line 1214

`type TCustomButton = class(TButtonControl)`
`protected`
`class procedure WSRegisterClass; override;` |  | Registers this component class with the current WidgetSet.
`procedure CreateWnd; override;` |  | Creates the handle for the widgetset class instance.
`procedure CreateParams(); override;` |  | Updates creation parameters to use values needed for the control.
`procedure ControlKeyDown(); override;` |  | Handles key down events for special navigation keys used in a control.
`procedure ControlKeyUp(); override;` |  | Handles key up events for special navigation keys.
`function DialogChar(); override;` |  | Handles an accelerator key for the control.
`function ChildClassAllowed(); override;` |  | Checks whether the specified class type is allowed as a child control.
`class function GetControlClassDefaultSize; override;` |  | Gets the default size for new instances of the control.
`property ParentColor: Boolean;` |  | Indicates if the parent color is used to draw the control.
`procedure WSSetDefault;` |  | Notifies the widgetset class of a change to the Default property.
`procedure WSSetText(); override;` |  | Notifies the widgetset class of a change to the caption text for the control.
`procedure TextChanged; override;` |  | Performs actions needed when the CM_TEXTCHANGED message is handled in the control.
`procedure Loaded; override;` |  | Performs actions needed when LCL component streaming has been completed.
`procedure UpdateDefaultCancel;` |  | Updates the Default and Cancel properties in the parent form.
`public`
`constructor Create(); override;` |  | Constructor for the class instance.
`procedure Click; override;` |  | Handles a button click event for the control.
`procedure ExecuteDefaultAction; override;` |  | Performs the Click method if the control is an Active or a Default button.
`procedure ExecuteCancelAction; override;` |  | Performs the Click method if the control is the Cancel button.
`procedure ActiveDefaultControlChanged(); override;` |  | Updates the button and/or parent form when the active default control has been changed.
`procedure UpdateRolesForForm; override;` |  | Internal method called by a Form when its DefaultControl or CancelControl has changed.
`function UseRightToLeftAlignment; override;` |  | True when BiDiMode is bdRightToLeft.
`property Active: Boolean; [rs]` |  | True if the control is the Cancel or Default button.
`property Default: Boolean; [rw]` |  | True if the button is the default button in a modal form.
`property ModalResult: TModalResult; [rw]` |  | Value returned when the control is clicked in a modal form.
`property ShortCut: TShortcut; [r]` |  | Shortcut key for the control.
`property ShortCutKey2: TShortcut; [r]` |  | Secondary shortcut key for the control.
`property Cancel: Boolean; [rw]` |  | True if the button is the modal Cancel button.
`property Color: TColor;` |  | Color used for the button face.
`property TabStop: Boolean;` |  | Enables keyboard navigation using the Tab or Shift+Tab keys.
`end;`

## Inheritance

`TCustomButton` |  | The base class for a push button control.
`TButtonControl` |  | Specifies a base class for button controls.
`TWinControl` |  | Implements a windowed control which can contain other child controls.
`TControl` |  | The base class for visible controls.
`TLCLComponent` |  | The base class for LCL components which have an associated widget.
`TComponent`
?
`TObject`

## Description

TCustomButton is a TButtonControl descendant which provides the base class for a push button control.

TCustomButton / TButton are used to perform an action when the control is clicked. An OnClick event handler is provided to perform actions needed when the push button is clicked.

Properties are provided to control the appearance and behavior for the control. This includes whether it is the Default or Cancel button on a modal form, and the modal result returned when the push button is clicked.

The control displays a text-based caption and is drawn using a style appropriate for the platform or widgetset. An accelerator key can be defined in the caption which simulates clicking on the push button when the shortcut key is pressed. Support for TBasicAction from the FPC Run-time Library (RTL) is present, but not published in the control.

Please note that the Caption is always center aligned on the push button. The values in properties like BiDiMode and UseRightToLeftAlignment are ignored in the control.

Please note that the Color for the control defaults to the system-defined color used for button controls (clDefault or clBtnFace).

Do not create instances of TCustomButton; use the TButton descendant instead.

Use TBitBtn for a push button control which displays a bitmap instead of a text-based caption.

Use TSpeedButton for a push button control which can remain in the pressed or down state.

## See also

TButton |  | Implements a push button control.
TButtonControl |  | Specifies a base class for button controls.