No, there is no automatic adjustment of the height of a TButton
offered by the VCL.
If you change the font of the button's caption, or make it multi-line, you typically have to adjust the button's height yourself explicitly.
As a comparison, TEdit
does have an AutoSize
property. This doesn't map to a feature of the Win32 EDIT control (like a window style), but is implemented purely in the VCL (see Vcl.StdCtrls.TCustomEdit.AdjustHeight()
).
However, I just discovered that the underlying Win32 BUTTON control does offer this functionality, via the BCM_GETIDEALSIZE
message or Button_GetIdealSize()
macro:
uses
..., Winapi.CommCtrl;
var
S: TSize;
begin
S.cx := Button1.Width;
if Button_GetIdealSize(Button1.Handle, S) then
Button1.Height := S.cy;
This will set the height given the button's current text and desired width. If S
is initially zeros, you get the button's preferred width and height.
It is not uncommon that a Win32 control offers more functionality than its VCL wrapper exposes, so it is often a good idea to have a look at the Win32 documentation, particularly the messages you can send to the control (and also its styles).