Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Add a bitmap to a menu item Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
05-Sep-02
Category
VCL-Menu
Language
Delphi 2.x
Views
84
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: William Gerbert

Add a bitmap to a menu item

Answer:

Just follow these steps:

Create a Picture and store it as a file 'img.bmp'. 
Use the SetMenuItemBitmaps API call to connect the Picture to the Menu with these 
parameters: 
MenuItemFile is the name given to the horizontal Menuitem, e.g. "File", "Edit", 
"Help" 
0,1 ... is the position of the item on which you want to place the bitmap. (start 
counting with 0) 
The first of the two bitmap handles is the one for the bitmap displayed for the 
unchecked menuitem 
The second bitmap handle is the one for the checked menuitem. They may be the same.

All this can by coded in the .Create of a form.

Try to make the picture not to large, or it will not be displayed completely. Only 
the right-top of the bitmap will be displayed.

Finally, here's the code:


1   var
2     Bmp1: TPicture;
3   
4     ...
5   
6     Bmp1 := TPicture.Create;
7     Bmp1.LoadFromFile('.\img.bmp');
8     SetMenuItemBitmaps(MenuItemTest.Handle, 0, MF_BYPOSITION,
9       Bmp1.Bitmap.Handle, Bmp1.Bitmap.Handle);

  ...


Don't forget to free the bitmap Bmp1 e.g. when you destroy your form.

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC