Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

Author Topic: [CLOSED] Custom PopUpMenu  (Read 2848 times)

Pe3s

• Jr. Member
• Posts: 96
« on: November 30, 2021, 09:45:16 pm »
How can I fix the code to get rid of this gray frame.
Code: Pascal  [Select][+][-]
1. procedure TForm1.PopupMenu1DrawItem(Sender: TObject; ACanvas: TCanvas;
2.   ARect: TRect; AState: TOwnerDrawState);
3. var
4.   x, y: Integer;
5. begin
7.
8.   if AState * [odSelected, odFocused] <> [] then begin
9.     ACanvas.Brush.Color := RGBToColor(216, 215, 255);
10.     ACanvas.Pen.Color := RGBToColor(190, 190, 230);
11.     ACanvas.Rectangle(ARect);
12.     //ACanvas.Font.Style := [fsBold];
13.   end
14.   else
15.     ACanvas.GradientFill(ARect, clSkyBlue, clSkyBlue, gdHorizontal);
16.
17.   x := 2;
18.   y := (ARect.Top + ARect.Bottom - ImageList1.Height) div 2;
20.
21.   x := x + ImageList1.Width + 4;
22.   ACanvas.Pen.Color := clGray;
23.   ACanvas.Line(x, ARect.Top, x, ARect.Bottom);
24.
25.   x := x + 4;
26.   y := (ARect.Top + ARect.Bottom - ACanvas.TextHeight('Tg')) div 2;
27.   ACanvas.Brush.Style := bsClear;
28.   ACanvas.TextOut(x, y,  TMenuItem(Sender).Caption);
29.
30. end;
« Last Edit: December 01, 2021, 07:52:15 pm by Pe3s »

jamie

• Hero Member
• Posts: 5129
« Reply #1 on: November 30, 2021, 10:46:10 pm »
I am not really sure if you can rid the frame..

It's obvious you are attempting a flat menu and even if you succeed in doing so you still have the shadow.

I have done this before but its not that simply..

what I did was get the top window and then do a screen draw around it to match the color you wish.

in windows you can play with the host window that is being used but this sure won't work across the pond.

I'll look in my old notes for this see if I can find something..
The only true wisdom is knowing you know nothing

Pe3s

• Jr. Member
• Posts: 96
« Reply #2 on: December 01, 2021, 07:38:34 am »
@Jamie My point was to fill the entire background of the menu with color.  I don't want to remove the shadow. Remove white border
« Last Edit: December 01, 2021, 01:33:51 pm by Pe3s »

jamie

• Hero Member
• Posts: 5129
« Reply #3 on: December 01, 2021, 02:44:10 pm »
Yes, I know exactly what you want and like I said, it will be futile

In any case if you want to play..

use "WindowFromDC(Canvas.Handle)"

That gives you the window the menu is drawing on..

Then use "GetWindowInfo(TheHandleThatwasReuturned, the WIndowINfo record);

In that you can find all the details about the window being used for the menu.

have fun.
The only true wisdom is knowing you know nothing

• Jr. Member
• Posts: 96