Hacking TPopup

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.
kapotAsked:
Who is Participating?
 
bokistConnect With a Mentor Commented:
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
 
carcotasuCommented:
0
 
kapotAuthor Commented:
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
 
kapotAuthor Commented:
bokist, I like your idea ! :)

Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.