Recent

Author Topic: [Solved] Query an image in a TPopupMenu  (Read 420 times)

petevick

  • Full Member
  • ***
  • Posts: 219
[Solved] Query an image in a TPopupMenu
« on: January 30, 2023, 06:57:54 pm »
I know that you'd add an image to a TPopupMenu by this code snippet....
Code: Pascal  [Select][+][-]
  1.   imgList:= TImageList(PopupMenu1.Images);
  2.   bmp:= TBitmap.Create;
  3.   PopupMenu1.Images.BeginUpdate;
  4.      try
  5.         imgList.GetBitmap(idx, bmp);
  6.         bmp.Canvas.Brush.Color := clBlue;
  7.         bmp.Canvas.Brush.Style := bsSolid;
  8.         bmp.Canvas.Rectangle(0, 0, bmp.Width, bmp.Height);
  9.         bmp.TransparentColor := clWhite;
  10.         bmp.TransparentMode := tmFixed;
  11.         bmp.Transparent := true;
  12.         imgList.ReplaceMasked(idx, bmp, clWhite);
  13.         finally
  14.         bmp.Free;
  15.         PopupMenu1.Images.EndUpdate;
  16.      end;

....but how would you query what the Canvas.Brush.Color is for any particular image in the TPopupMenu ?
I was originally thinking it'd probably be a similar code structure to the above, but now I'm not so sure  :-\
It might not even be possible of course  %)
« Last Edit: January 30, 2023, 08:51:57 pm by petevick »
Pete Vickerstaff
Linux Mint 21.1 Cinnamon, Lazarus 2.2.0, FPC 3.2.2

GetMem

  • Hero Member
  • *****
  • Posts: 4071
Re: Query an image in a TPopupMenu
« Reply #1 on: January 30, 2023, 08:17:54 pm »
Since Idx represents a unique image in the ImageList, save the Brush.Color to a dynamic array. Retrieve with FBrushColor(idx).


petevick

  • Full Member
  • ***
  • Posts: 219
Re: Query an image in a TPopupMenu
« Reply #2 on: January 30, 2023, 08:51:26 pm »
Since Idx represents a unique image in the ImageList, save the Brush.Color to a dynamic array. Retrieve with FBrushColor(idx).
Thanks for the reply GetMem. I get an
Quote
Error: Identifier not found "FBrushColor"
But your suggestion of saving to a dynamic array got me out of the hole I was in. My array is a TColor so to retrieve I just use....
Code: Pascal  [Select][+][-]
  1. Abutton.Color := Pcol[idx];

...which works a treat.
Thanks yet again for your help GetMem  ;)
Pete Vickerstaff
Linux Mint 21.1 Cinnamon, Lazarus 2.2.0, FPC 3.2.2

 

TinyPortal © 2005-2018