上下文菜单条带宽度
我需要动态更改 contextmenustrip 宽度,默认情况下 contextmenustrip 宽度取决于 ToolstripmenuItems 的文本长度。
顺便说一句,我真的不想再次重绘控件!
提前致谢。
I need to change the contextmenustrip width dynamically, by default the contextmenustrip width depends on the text length of the ToolstripmenuItems.
And BTW I really don't wanna redraw the control again!!!
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将 ContextMenuStrip AutoSize 属性设置为 false。 然后您可以将 Width 属性设置为您想要的任何值。 当 AutoSize 设置为 true 时,Width 属性将被忽略并动态计算。
例子:
You need to set the ContextMenuStrip AutoSize property to false. Then you can set the Width property to whatever you want. When AutoSize is set to true, the Width property is ignored and is calculated dynamically.
Example:
无论如何,AutoSize 在猜测“正确”尺寸方面做得非常糟糕。
当为 TRUE 时,菜单比任何文本所需的都要宽。
当您手动设置时...您还必须将 HEIGHT 设置为远小于您的预期...如果您希望它显示在正确大小的菜单中。
AutoSize does a VERY poor job of guessing at the "correct" size anyway.
When TRUE, the menu is far wider than any of the text would need it to be.
When you set it manually... you also have to set the HEIGHT to be far less than you would expect... if you want it to display in the correct size menu.