[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Popup menu border

Posted on 2004-12-01
4
Medium Priority
?
1,005 Views
Last Modified: 2010-04-05
Hi.

Simply put, I want to be able to show popup menus with solid borders, with my choice of thickness and colour.

Thanks,

MoonCalf.
0
Comment
Question by:MoonCalf
  • 2
  • 2
4 Comments
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12718382
AFAIK, the popup class doesn't have a customdraw method and doesn't even provide you any way to draw it yourself with simple events. I think it cannot be done, unless you want to write your own code for it. (E.g. by displaying a panel, drawing the menuoptions on this panel any way you like them and use OnClick events to respond to menu-options. But then this isn't a real popup anymore.)
0
 
LVL 1

Author Comment

by:MoonCalf
ID: 12722096
Erm, thanks alex, but I've already done a lot of drawing on the menus.  If you google you'll find lots of examples of custom-drawing on menus, both standard and popup.
0
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 500 total points
ID: 12725608
Ah, I see. I was looking at the wrong location... :-)
Well, in that case you already know the answer... Use the CustomDraw event of the menu item... The simplest way to do this is by assigning one single OnDraw event to all the menu-items in your messagelist. The sender will be the menu item that wants to be drawn so use it to get the caption. If you want to draw a box around the whole popup menu then you have to look if the menu-item happens to be the first or last in the list. If so, you should draw the sides and either the top or bottom border. If it's not, draw only the sides.
Set the Popup OwnerDraw to True and on e.g. the FormCreate, call this code:

  for I := 0 to pred( PopupMenu1.Items.Count ) do
    PopupMenu1.Items[ I ].OnAdvancedDrawItem := GlobalAdvancedDrawItem;

And of course, add the GlobalAdvancedDrawItem function:

procedure TFormMain.GlobalAdvancedDrawItem( Sender: TObject; ACanvas: TCanvas; ARect: TRect; State: TOwnerDrawState );
var
  MenuItem: TMenuItem;
begin
  if Sender.InheritsFrom( TMenuItem ) then begin
    MenuItem := TMenuItem( Sender );
    if ( MenuItem.MenuIndex = 0 ) then begin
      DrawEdge( ACanvas.Handle, ARect, EDGE_ETCHED, BF_LEFT or BF_RIGHT or BF_TOP );
    end
    else if ( MenuItem.MenuIndex = Pred( MenuItem.Parent.Count ) ) then begin
      DrawEdge( ACanvas.Handle, ARect, EDGE_ETCHED, BF_LEFT or BF_RIGHT or BF_BOTTOM );
    end
    else begin
      DrawEdge( ACanvas.Handle, ARect, EDGE_ETCHED, BF_LEFT or BF_RIGHT );
    end;
    ARect.Left := ARect.Left + 2;
    ARect.Top := ARect.Top + 2;
    ARect.Right := ARect.Right - 2;
    ARect.Bottom := ARect.Bottom - 2;
    ACanvas.TextRect( ARect, ARect.Left, ARect.Top, MenuItem.Caption );
  end;
end;

Of course, you could use your own drawing technique. Also, above code doesn't check if items are hidden of if there's only one menu-item in the list. It needs more work... Use the canvas methods to draw whatever you like but also make sure to set the OnMeasureItem event if you want to make it a bit bigger. You have to make sure that whatever you draw will fit.
0
 
LVL 1

Author Comment

by:MoonCalf
ID: 12736197
Thanks alex - with a bit of jigging around I can get that working with what I've already done.

Cheers mate,

MoonCalf.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question