如何使上下文菜单项的高度不会在.net固定(即规模为特定项目的大小)? [英] How do you make height of context menu items not be fixed (ie scale to size of the particular item) in .Net?

查看:142
本文介绍了如何使上下文菜单项的高度不会在.net固定(即规模为特定项目的大小)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参阅下面的两张图片。我不想在菜单中的每个项目是最大的高度。它应该大小以适合的内容。我打得周围的一些属性,并未能prevent此行为。这可能吗?

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?

推荐答案

设置的 MenuItem.OwnerDraw 为true,那么处理的 MenuItem.MeasureItem 事件。这允许你告诉Windows窗体别人的大小这个菜单项的大小独立,尽管不必再自己呈现项目的成本。

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.

请注意这样做的没有的导致自动大小到合适:你将需要使用GDI +函​​数来计算所需的大小

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

这篇关于如何使上下文菜单项的高度不会在.net固定(即规模为特定项目的大小)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆