Solved

Image in Popup menu

Posted on 2002-06-05
7
437 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 89
Reconfigure Delphi Install? 2 51
Firemonkey webbrowser scrollbars ? 1 38
Sending files from  idTcpServer Socket to idTcpClient 2 40
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…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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