C# 如何删除 MenuStrip 子菜单边距?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/853873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 04:16:29  来源:igfitidea点击:

How to remove MenuStrip submenu margins?

c#menustrip

提问by kyrisu

Do you know how to remove margin (probably the one for image and check box on the left and right) of the submenu in MenuStri? In MSDN articlethere is explained how to remove it from context menus. It is written that I should do it the same way in MenuStrip but MenuStrip do not have ShowImageMargin nor ShowCheckMargin. Maybe I'm missing something. Can you help?

你知道如何去除MenuStri中子菜单的边距(可能是图像和左右复选框的边距)吗?在MSDN 文章中,解释了如何从上下文菜单中删除它。据说我应该在 MenuStrip 中以相同的方式执行此操作,但 MenuStrip 没有 ShowImageMargin 和 ShowCheckMargin。也许我错过了一些东西。你能帮我吗?

采纳答案by SLA80

Very similar, but instead of using "ContextMenuStrip" (which is used in your MSDN article), you have to use "ToolStripDropDownMenu". This way:

非常相似,但不是使用“ContextMenuStrip”(在您的MSDN 文章中使用),您必须使用“ ToolStripDropDownMenu”。这边走:

((ToolStripDropDownMenu)noMargins.DropDown).ShowImageMargin = false;

For example, if you want to remove all image margins from your menubar called "menuStrip1", add this code to your form initialization routine:

例如,如果您想从名为“menuStrip1”的菜单栏中删除所有图像边距,请将以下代码添加到表单初始化例程中:

// Removing image margins (space for icons on left) from menubar items:
foreach (ToolStripMenuItem menuItem in menuStrip1.Items)
    ((ToolStripDropDownMenu)menuItem.DropDown).ShowImageMargin = false;