unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, BCButton, Forms, Controls, Graphics, Dialogs,
Types, BGRABitmap, BGRABitmapTypes;
type
{ TForm1 }
TForm1 = class(TForm)
BCButton1: TBCButton;
BCButton2: TBCButton;
ImageList32: TImageList;
procedure BCButton1AfterRenderBCButton(Sender: TObject;
const ABGRA: TBGRABitmap; AState: TBCButtonState; ARect: TRect);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.BCButton1AfterRenderBCButton(Sender: TObject;
const ABGRA: TBGRABitmap; AState: TBCButtonState; ARect: TRect);
var
myText: string;
myRect: TRect;
tw: integer;
c: TBGRAPixel;
begin
{ Custom painting of Caption and Image needed, as standard routines misalign the
position of Caption and Image }
ABGRA.FontName := 'Segoe UI';
ABGRA.FontHeight := 14;
myText := TBCButton(Sender).Caption;
{ Defining myRect with Bottom -12px }
myRect.Bottom := ARect.Bottom - 12;
myRect.Left := ARect.Left;
myRect.Right := ARect.Right;
myRect.Top := ARect.Left;
{ Determining the width/height of Caption. We need only width }
tw := ABGRA.TextSize(mytext).cx;
c := clRed;
if tw > TBCButton(Sender).Width then
begin
{ Caption doesnt fit in one line, reduce Fontsize }
ABGRA.FontHeight := 13;
ABGRA.TextRect(ARect, myText, taCenter, tlBottom, c);
end
else
begin
{ Caption fits in one line }
ABGRA.TextRect(myRect, myText, taCenter, tlBottom, c);
end;
{ Painting of Image on Button }
ImageList32.Draw(ABGRA.Canvas, (TBCButton(Sender).Width - 32) div 2, 4,
TBCButton(Sender).ImageIndex);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
BCButton1.ShowCaption := False;
BCButton1.Images := nil;
BCButton2.ShowCaption := False;
BCButton2.Images := nil;
end;
end.