Recent

Author Topic: Problem with button Bagra  (Read 1014 times)

essam eddine adib

  • New Member
  • *
  • Posts: 20
Problem with button Bagra
« on: July 03, 2019, 09:11:43 am »
Hi,

I want to have a button with centered glyph and label in bottom or top but when i choose cabottomcenter for label it center it compared to free space let by glyph.
i join screen to what i have and what i want to have
(By changing code in source code i obtain what i want but it not recommended


thank's for help

coasting

  • New member
  • *
  • Posts: 9
Re: Problem with button Bagra
« Reply #1 on: July 03, 2019, 11:04:20 am »
The standard routines misalign the position of Caption and Image. Have a look into the Ribbon Demo provided with the BGRA package.

essam eddine adib

  • New Member
  • *
  • Posts: 20
Re: Problem with button Bagra
« Reply #2 on: July 04, 2019, 06:30:20 pm »
thank you for response I saw what they do in in BGRA ribbon example but i could not reproduce it in new project

can U help me

thank's a lot

coasting

  • New member
  • *
  • Posts: 9
Re: Problem with button Bagra
« Reply #3 on: July 05, 2019, 11:14:42 am »

See an example here below and attached...

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, BCButton, Forms, Controls, Graphics, Dialogs,
  9.   Types, BGRABitmap, BGRABitmapTypes;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     BCButton1: TBCButton;
  17.     BCButton2: TBCButton;
  18.     ImageList32: TImageList;
  19.     procedure BCButton1AfterRenderBCButton(Sender: TObject;
  20.       const ABGRA: TBGRABitmap; AState: TBCButtonState; ARect: TRect);
  21.     procedure FormCreate(Sender: TObject);
  22.   private
  23.     { private declarations }
  24.   public
  25.     { public declarations }
  26.   end;
  27.  
  28. var
  29.   Form1: TForm1;
  30.  
  31. implementation
  32.  
  33. {$R *.lfm}
  34.  
  35. { TForm1 }
  36.  
  37. procedure TForm1.BCButton1AfterRenderBCButton(Sender: TObject;
  38.   const ABGRA: TBGRABitmap; AState: TBCButtonState; ARect: TRect);
  39. var
  40.   myText: string;
  41.   myRect: TRect;
  42.   tw: integer;
  43.   c: TBGRAPixel;
  44. begin
  45. { Custom painting of Caption and Image needed, as standard routines misalign the
  46.   position of Caption and Image }
  47.  
  48.   ABGRA.FontName := 'Segoe UI';
  49.   ABGRA.FontHeight := 14;
  50.  
  51.   myText := TBCButton(Sender).Caption;
  52.  
  53.   { Defining myRect with Bottom -12px }
  54.   myRect.Bottom := ARect.Bottom - 12;
  55.   myRect.Left := ARect.Left;
  56.   myRect.Right := ARect.Right;
  57.   myRect.Top := ARect.Left;
  58.  
  59.   { Determining the width/height of Caption. We need only width }
  60.   tw := ABGRA.TextSize(mytext).cx;
  61.   c := clRed;
  62.  
  63.   if tw > TBCButton(Sender).Width then
  64.   begin
  65.     { Caption doesnt fit in one line, reduce Fontsize }
  66.     ABGRA.FontHeight := 13;
  67.     ABGRA.TextRect(ARect, myText, taCenter, tlBottom, c);
  68.   end
  69.   else
  70.   begin
  71.     { Caption fits in one line }
  72.     ABGRA.TextRect(myRect, myText, taCenter, tlBottom, c);
  73.   end;
  74.  
  75.   { Painting of Image on Button }
  76.   ImageList32.Draw(ABGRA.Canvas, (TBCButton(Sender).Width - 32) div 2, 4,
  77.     TBCButton(Sender).ImageIndex);
  78. end;
  79.  
  80. procedure TForm1.FormCreate(Sender: TObject);
  81. begin
  82.   BCButton1.ShowCaption := False;
  83.   BCButton1.Images := nil;
  84.   BCButton2.ShowCaption := False;
  85.   BCButton2.Images := nil;
  86. end;
  87.  
  88. end.
  89.  
                                 

 

TinyPortal © 2005-2018