views:

98

answers:

1

See the two images below. I don't want each item in the menu to be the height of the largest. It should size to fit the contents. I've played around with a number of properties and haven't been able to prevent this behavior. Is it possible?

Desired Height Fixed Height For all!

+1  A: 

Set MenuItem.OwnerDraw to true, then handle the MenuItem.MeasureItem event. This allows you to tell Windows Forms the size of this menu item independently of the size of others, albeit at the cost of having to then render the item yourself.

Note this does not result in automatic size-to-fit: you will need to use GDI+ functions to calculate the desired size.

itowlson
In my case... wouldn't i then need to handle the MenuItem.MeasureItem event for all the contenxt menu items EXCEPT for the top one (the big one)?
blak3r
I believe that menu items that are not owner-draw would get the default menu item size. By leaving the "Windows-managed" text -- i.e. the MenuItem.Text property -- of the owner-draw item empty you would avoid bloating this default size. (You could still draw whatever text you wanted into the menu item rectangle.) However, I haven't tested this so you might need to test it! But if I'm wrong then you can as you say address this by custom-measuring all the menu items -- though this would be rather tedious.
itowlson