问题描述
请参阅下面的两张图片。我不想在菜单中的每个项目是最大的高度。它应该大小以适合的内容。我打得周围的一些属性,并未能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?
推荐答案
设置的为true,那么处理的事件。这允许你告诉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固定(即规模为特定项目的大小)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!