Recent

Author Topic: 2023: How to change TMenu or TPopup properties like font size or color?  (Read 678 times)

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 451
  • Programming is FUN only when it works :)
    • Cool Technology
Hi,

I need to change the font size or the font color of a popup menu on my form. I have gone up and down on the Internet and on this forum and I can't seem to find any working solution for my problem... I can't get the Popup Menu font size or its font name changed.

I set the OwnerDraw :=true and then assign handlers as follows.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.PopupMenu1DrawItem(Sender: TObject; ACanvas: TCanvas;
  2.   ARect: TRect; AState: TOwnerDrawState);
  3. var
  4.   s: string;
  5. begin
  6.   // change font
  7.   ACanvas.Font.Name := 'Times';
  8.   ACanvas.Font.Size := 20;
  9.   ACanvas.Font.Style := [fsBold];
  10.   ACanvas.Font.Color := clYellow;
  11.   // change background
  12.   ACanvas.Brush.Color := clBlack;
  13.   ACanvas.Rectangle(ARect);
  14.   // write caption/text
  15.   s := (Sender as TMenuItem).Caption;
  16.   ACanvas.TextOut(ARect.Left + 2, ARect.Top + 2 , s);
  17. end;
  18.  
  19.  

And I see NO CHANGES AT ALL. Besides, I noticed that drawitem and measureitem handler is not EXECUTING at all.

Any idea.
fpc 3.2.0
laz 2.0.10
« Last Edit: August 30, 2023, 02:49:21 pm by Awesome Programmer »

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
It probably does not work on all widgetsets. It does nothing on Qt4 and GTk2.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018