Recent

Author Topic: TMainMenu Ownerdraw - How to paint the background?  (Read 4932 times)

knuckles

  • Full Member
  • ***
  • Posts: 122
TMainMenu Ownerdraw - How to paint the background?
« on: September 20, 2017, 02:02:42 am »
Hi, I noticed TMainMenu allows to ownerdraw so I experiment a little with this like so:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.MainMenu1DrawItem(Sender: TObject; ACanvas: TCanvas;
  2.   ARect: TRect; AState: TOwnerDrawState);
  3. begin
  4.   ACanvas.GradientFill(ARect, clSilver, clWhite, gdVertical);
  5. end;

Of course there is no code here for checking the state of the items etc I will handle those later, the main thing I would like to know is how to paint the menu background? I can only see a way of painting the menu items not the actual background? And I dont mean the item background, but the menu strip if you like to call it that, eg from 0 position to form clientwidth.

This routine is also named DrawItem so I know I cannot paint the background here but equally i see no other place to do this?

Any suggestions or is it simply not possible?

knuckles

  • Full Member
  • ***
  • Posts: 122
Re: TMainMenu Ownerdraw - How to paint the background?
« Reply #1 on: September 20, 2017, 11:09:14 am »
To clarify I have included a screenshot, as you can see the gradient only paints where items exist. What I hoped to achieve is paint the whole area highlighted in orange, and then paint the menu items seperately but I see no way of painting the background, just the items only?

knuckles

  • Full Member
  • ***
  • Posts: 122
Re: TMainMenu Ownerdraw - How to paint the background?
« Reply #2 on: September 21, 2017, 12:35:15 pm »
So for the sake of it I added a little extra basic code but in the end I think I will abandon this, not only is painting the actual background proving difficult to impossible I also see no obvious way to draw the menu captions back.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.MainMenu1DrawItem(Sender: TObject; ACanvas: TCanvas;
  2.   ARect: TRect; AState: TOwnerDrawState);
  3. begin
  4.   ACanvas.GradientFill(ARect, clSilver, clWhite, gdVertical);
  5.  
  6.   if (odSelected in AState) then
  7.   begin
  8.     ACanvas.Brush.Color := $00F3DBBC;
  9.     ACanvas.Pen.Color := $00EBB983;
  10.     ACanvas.Rectangle(ARect);
  11.   end;
  12.  
  13.   ACanvas.TextOut(ARect.Left + 3, ARect.Top + 3, 'test');
  14. end;  

So I guess what I need is a 3rd party menu and Toolbar I guess but I don't seem able to find any, something like toolbar97 or SXSkinComponents I think it was called which allowed OfficeXP menu and toolbar themes etc would have been a good test.

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: TMainMenu Ownerdraw - How to paint the background?
« Reply #3 on: September 21, 2017, 02:33:08 pm »
Set the Brush.Style to bsClear to paint transparent text.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: TMainMenu Ownerdraw - How to paint the background?
« Reply #4 on: September 21, 2017, 02:53:23 pm »
which control is that? TMainmenu in my installation of lazarus 1.6.4 and 1.4.4 does not have an OnDrawItem event.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

knuckles

  • Full Member
  • ***
  • Posts: 122
Re: TMainMenu Ownerdraw - How to paint the background?
« Reply #5 on: September 21, 2017, 03:22:36 pm »
Set the Brush.Style to bsClear to paint transparent text.

Yes I know this, this was just quick test :)

knuckles

  • Full Member
  • ***
  • Posts: 122
Re: TMainMenu Ownerdraw - How to paint the background?
« Reply #6 on: September 21, 2017, 03:23:28 pm »
which control is that? TMainmenu in my installation of lazarus 1.6.4 and 1.4.4 does not have an OnDrawItem event.

Ah sorry I should have said this is Lazarus 1.8RC4 the standard TMainMenu component

 

TinyPortal © 2005-2018