Icons in Application Menus

S

Siv

Hi,
I have just searched MSDN and Google and can't find a tutorial about how to
add icons to menus in a VB.NET or C#.NET Windows Forms application.
Does anyone know how it's done or can point me at a tutorial that is easy to
follow.

In anticipation, thanks.

Graham Sivill
Martley, Near Worcetser UK.
 
J

James Jardine

Siv said:
Hi,
I have just searched MSDN and Google and can't find a tutorial about how
to add icons to menus in a VB.NET or C#.NET Windows Forms application.
Does anyone know how it's done or can point me at a tutorial that is easy
to follow.

In anticipation, thanks.

Graham Sivill
Martley, Near Worcetser UK.

You have to set the OwnerDraw property on the menu item. Then override the
onPaint method I believe. here is a link that shows an example of this.
Their menus are not that pretty but it should give you an idea of how to do
this. The sample is in C#, Sorry that is the first I found. Should be an
easy conversion though.
http://www.c-sharpcorner.com/Code/2002/April/OwnerDrawMenusSK.asp
 
S

Siv

James,
Thanks, all I could find was an old VB6 example that looked a bit Windows
API for me!

Graham Sivill
Martley, Near Worcester, UK
 
H

Herfried K. Wagner [MVP]

Siv said:
I have just searched MSDN and Google and can't find a tutorial about how
to add icons to menus in a VB.NET or C#.NET Windows Forms application.
Does anyone know how it's done or can point me at a tutorial that is easy
to follow.

Which version of the .NET Framework are you using? If you are using .NET
Framework 2.0 (VS 2005), simply use the built-in MenuStrip control.
 
S

Siv

Herfried,
I am using VB.NET 2005 with the 2.0 Framework, could you explain how the
menustrip works, I thought they were for creating pop-up menus?
Siv
 
H

Herfried K. Wagner [MVP]

Siv said:
I am using VB.NET 2005 with the 2.0 Framework, could you explain how the
menustrip works, I thought they were for creating pop-up menus?

Simply place a menustrip control on the form :). You can use the new menu
control for popup menus too.
 
S

Siv

Herfried,

Once I figured out how to get it to dock to the top of the form I got it
working. I tried using some of the bitmaps from the "Command" section of
the VS2005 Image Library. At the moment they appear in the menu with a
magenta background, I haven't run the app yet as I have some code that needs
tidying up before running. I assume the magenta bit will appear
transparent? If not how do I get the icons to appear as normal?

As always, thanks for your help!

Siv
 
H

Herfried K. Wagner [MVP]

Siv said:
I tried using some of the bitmaps from the "Command" section of the
VS2005 Image Library. At the moment they appear in the menu with a magenta
background, I haven't run the app yet as I have some code that needs
tidying up before running. I assume the magenta bit will appear
transparent? If not how do I get the icons to appear as normal?

Set the menu items' 'ImageTransparentColor' property to magenta.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top