Solved

Image in Popup menu

Posted on 2002-06-05
7
466 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: 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!

 
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: 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.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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