English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

What is the concept behind designing menus with icons in vb.net? I know it has to do with something called owner drawing, but what exactly is that?

Lets me say that I've simply created some menu items in design time in vb.net 2003. Now how do I code so that I can associate it with icons?

Can some one explain the functions used and why we are using them?

Ideally I would like the step by step process with explanation.

2007-01-13 00:58:44 · 1 answers · asked by deostroll 3 in Computers & Internet Programming & Design

1 answers

What OwnerDraw is the the owner(in this case, the form) drawing the item instead of the control's (menuitem) own internal drawing methods. Using OwnerDraw you will have much more flexibility as to how appears and how it appears. For instance you can change the font size, style, etc. You can also change other things like the background color. You are pretty much only limited by your imagination. There is, however, one thing you can NOT change. If you have a MenuItem with sub items I am sure you recall that a right facing triangle appears to the right of your text to inform you that selecting this item opens a sub menu. This triangle cannot be changed using OwnerDraw.

With that aside, there are 2 events you have to be aware of when using OwnerDraw. The first is DrawItem and the second is MeasureItem. The MeasureItem event for the menuitem is where you will calculate the size of the menuitem and assign the values for the MeasureItemEventArg Height and Width. It should be simple for you to determine the height and width of your icon but to determine the size of your text, you will need to use the MeasureString method of MeasureItemEventArg.Graphics You can look up all the parameters in the IDE.

The next event that would fire is the DrawItem event for the MenuItem. This one can get a bit more complicated depending on your requirements. I strongly suggest that you do a google search on this event to get more information or check the search in the VS IDE for information on this event. If you do not plan on allowing menuitems to be disabled, etc then much of the complicated aspect goes away. Things to keep in mind is that you will need to create a rectangle, fill it, and then draw the icon and the text (using DrawString for the text).

You will more than likely want to play around with the events to work out spacing and whatnot. Once you begin playing with it, it should start to make sense. Don't forget that you need to set the OwnerDraw property to TRUE for each menuitem in which you want to override its appearance.

2007-01-13 01:58:15 · answer #1 · answered by Scottee25 4 · 0 0

fedest.com, questions and answers