[Solved] How to change popup menu row background color? lazarus / 31-LCL ---------------------------------------------------------------------- loaded · 2023-09-19 09:15 Hi All, In a project I'm working on, I have a popup menu with a lot of content. I want to change the background colors so that I can easily find the ones I use most. Is it possible to do this with simple methods? ---------------------------------------------------------------------- KodeZwerg · 2023-09-19 10:41 This is how you can colorize your items: 1. Create your MenuItems with Designer and apply to each Item that you want to colorize a different Tag number, let it 0 to be unchanged 2. Create a OnDraw handler for the PopupMenu1 3. Copy and paste this code into that handler: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.PopupMenu1DrawItem(Sender: TObject; ACanvas: TCanvas;  ARect: TRect; AState: TOwnerDrawState);var  MenuItem: TMenuItem;begin  if (Sender is TMenuItem) then    begin      MenuItem := (Sender as TMenuItem);      ACanvas.Brush.Style := bsClear;      case MenuItem.Tag of        1: ACanvas.Brush.Color := clRed;        2: ACanvas.Brush.Color := clSkyBlue;        3: ACanvas.Brush.Color := clMoneyGreen;        else          ACanvas.Brush.Color := clNone;    end;      ACanvas.FillRect(ARect);      ACanvas.TextRect(ARect, ARect.Left + 5, ARect.Top + 2, MenuItem.Caption);    end;end;4. Remove the handler from PopupMenu1 again 5. Assign this handler now to all MenuItems 6. Run app. ---------------------------------------------------------------------- loaded · 2023-09-19 11:19 Thank you very much for your answer KodeZwerg This trick never occurred to me; I think it's because of old age. ---------------------------------------------------------------------- KodeZwerg · 2023-09-19 12:14 Quote from: loaded on September 19, 2023, 01:19:40 pmThank you very much for your answer KodeZwerg This trick never occurred to me; I think it's because of old age.  You are welcome, lets expand this "trick" a little more: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  MenuItem: TMenuItem;begin  if (Sender is TMenuItem) then    begin    MenuItem := (Sender as TMenuItem);      ACanvas.Brush.Style := bsClear;      case MenuItem.Tag of        1: if odSelected in AState then             ACanvas.Brush.Color := clHighlight           else           ACanvas.Brush.Color := clRed;        2: if odSelected in AState then             ACanvas.Brush.Color := clHighlight           else             ACanvas.Brush.Color := clSkyBlue;        3: if odSelected in AState then             ACanvas.Brush.Color := clHighlight           else             ACanvas.Brush.Color := clMoneyGreen;        else          if odSelected in AState then           ACanvas.Brush.Color := clHighlight           else             ACanvas.Brush.Color := clNone;      end;      if odSelected in AState then        ACanvas.Font.Style := [fsBold]      else        ACanvas.Font.Style := [];      ACanvas.FillRect(ARect);      ACanvas.TextRect(ARect, ARect.Left + 5, ARect.Top + 2, MenuItem.Caption);    end;end;Now the items are colored differently while you hover with mouse or cursor-keys over an item (and the font is a little bigger) Feel free to add more different things for different states, like odDisabled ... let your imagination no limits on that