Recent

Author Topic: Align button caption  (Read 3746 times)

Hansvb

  • Hero Member
  • *****
  • Posts: 618
Align button caption
« on: April 24, 2015, 11:03:40 pm »
The caption is alway in the middle of the button. How to align the caption to the left?

BitBangerUSA

  • Full Member
  • ***
  • Posts: 183
Re: Align button caption
« Reply #1 on: April 25, 2015, 01:36:18 am »
kludge way - add spaces to the right of the Caption.
Lazarus Ver 2.2.6 FPC Ver 3.2.2
Windows 10 Pro 64-bit

dietmar

  • Full Member
  • ***
  • Posts: 170
Re: Align button caption
« Reply #2 on: April 25, 2015, 01:52:56 am »
I found an older thread regarding this issue, perhaps it is a help for you:

http://forum.lazarus.freepascal.org/index.php?topic=21647.0

Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Align button caption
« Reply #3 on: April 25, 2015, 02:05:59 am »
For a "standard" pushbutton, I'm not sure it's possible with the LCL (it's different for the other non-native buttons that are "painted").

Windows only solution (don't know if it's possible for the other OS): modify the style of the existing button using the Windows API.

Demonstration code:
Code: [Select]
...
uses
  Windows;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SetWindowLongPtr(Button1.Handle, GWL_STYLE, GetWindowLongPtr(Button1.Handle, GWL_STYLE) and (not BS_CENTER) or BS_LEFT);
  Button1.Refresh;
end;
...
« Last Edit: April 25, 2015, 02:40:26 am by ChrisF »

Hansvb

  • Hero Member
  • *****
  • Posts: 618
Re: Align button caption
« Reply #4 on: April 25, 2015, 10:27:00 pm »
i followed the link. The examples only work on TButton. i use TBitbtn.

 

TinyPortal © 2005-2018