Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Hacking TPopup

Posted on 2009-02-23
4
Medium Priority
?
257 Views
Last Modified: 2012-05-06
Hi,

Recently, I read an article about how to customize (change color) of TPopup:
http://delphi.about.com/od/vclusing/a/owner_drawing.htm

But it must be done on each menu item. It is ok if I have only small number of menu items.

Is there any way to move the DrawItem to the TPopup object?

For drawing the icon, we can check the Caption (for example):

if menu caption = 'abc' then drawIcon(5) ...

Thanks.
0
Comment
Question by:kapot
  • 2
4 Comments
 
LVL 1

Expert Comment

by:carcotasu
ID: 23710996
0
 

Author Comment

by:kapot
ID: 23711379
Thanks for the info, but this is not what I want.

The thing is ... I want to be able to use PNG on the TPopup menu item icon.

This can be achieved if I use TPNGImageList from PNGComponents.

However, not all TPopup components compatible with it, for example JEDI-VCL.

Standard TPopup works fine.

I know how to use OnDrawItem in the menu item ... but thats too much to do for all menu items of all TPopup objects.

I thought if there is a way to add event OnDrawItems (for example) in the TPopup object.

NOTE:
BarMenu: I dont like it
TBX: it does not have popup menu
XPMenu: it does not have popup menu
0
 
LVL 6

Accepted Solution

by:
bokist earned 500 total points
ID: 23714608
try this solution

set popupmenu OwnerDraw := True;

on each popupitem OnDrawItem set : PopupMenuDrawItem

then

procedure TForm1.PopupMenuDrawItem(Sender: TObject;
          ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
begin
  with (Sender as TMenuItem) do
     begin
     if Selected  then
        begin
        Acanvas.Brush.Color := clRed;
        Acanvas.Font.Style  := [fsBold];
        end
     else  begin
        Acanvas.Font.Style := [];
        Acanvas.Brush.Color := $00BAD9FE;
    end;
    ACanvas.FillRect(Arect);
    DrawText(ACanvas.Handle, PChar((Sender as Tmenuitem).Caption), -1, ARect, DT_VCENTER or DT_SINGLELINE or DT_Center);
  end;
end;
0
 

Author Comment

by:kapot
ID: 23719823
bokist, I like your idea ! :)

Thanks.
0

Featured Post

Industry Leaders: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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.…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

810 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