Solved

Image in Popup menu

Posted on 2002-06-05
7
453 Views
Last Modified: 2010-04-04
is there a way i can place an image (of the size of a menu item) in popup menu?
0
Comment
Question by:sazehra
7 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7058497
do you mean an icon before the menuitem
or for the whole menuitem-line?
0
 
LVL 1

Accepted Solution

by:
alx512 earned 50 total points
ID: 7058499
What version of Delphi do you have?
In Delphi 6 standart VCL components have appropriate properties. ImageList in TPopupMenu and ImageIndex in TMenuItem. If you use the older version of Delphi you must assign a method to OnDrawItem event of TMenuItem.


procedure TMainForm.N22DrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
var
  S: String;
  r: TRect;
begin
  CopyRect(r, ARect);
  s := TMenuItem(Sender).Caption;
  with ACanvas do
  begin
    FillRect(r);
    ImageList1.Draw(ACanvas, r.Left + 2, r.Top, 0);
    r.Left := r.Left + 18;
    DrawText(ACanvas.Handle, PChar(S), -1, r, DT_VCENTER or DT_SINGLELINE);
  end;
end;

0
 

Author Comment

by:sazehra
ID: 7058537
i am using Delphi 5 and i want to place a gif/bmp image on the whole menu item line.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 1

Expert Comment

by:alx512
ID: 7058556
The method above will work fine. Try it.
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7059926
you could also check out Jouni Airaksinens bcBarMenus
http://mintus.codefield.com/download/BarMenus/
0
 

Author Comment

by:sazehra
ID: 7064075
the bar menus were nice but the code that did the trick for me was

procedure TForm1.N1DrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
var
  bmp:TBitMap;
begin
  bmp:= TBitMap.Create;
  bmp.LoadFromFile('c:\temp\bmp.bmp');
  ACanvas.Draw(1,1, bmp);
end;

Thanks alx512 to set me on the right path...
0
 

Author Comment

by:sazehra
ID: 7064079
the bar menus mentioned by Lee were nice but the code that did the trick for me was

procedure TForm1.N1DrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
var
 bmp:TBitMap;
begin
 bmp:= TBitMap.Create;
 bmp.LoadFromFile('c:\temp\bmp.bmp');
 ACanvas.Draw(1,1, bmp);
end;

Thanks alx512 to set me on the right path...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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