在 MenuStrip 中添加水平分隔符
我似乎找不到任何方法在 MenuStrip 中添加水平分隔符。 Visual Studio 抱怨无法将 ToolStropSeparator 添加到 MenuStrip。
知道我该怎么做吗?
I can't seem to find any way to add a horizontal separator in a MenuStrip. Visual Studio complains Cannot add ToolStropSeparator to MenuStrip.
Any idea's how I can do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
在您想要用分隔线分隔的两个字段之间的空间中,键入:
然后按 Enter 键(在设计器中)
如果您需要以编程方式执行此操作,您可以使用相同的技巧:
In the space between the two fields you want separated by the divider, type:
then hit enter (in the designer)
If you need to do this programmatically you can use the same trick:
我能够运行这样的代码:
没有任何问题...您遇到了什么类型的错误?
I'm able to run code like this:
without any trouble... What kind of error are you getting?
您可以右键单击菜单栏,然后选择“插入”-> '分隔器'。
就这样。
You can right-click the menustrip, then 'Insert' -> 'Separator'.
That's all.
我的一个项目遇到了问题,我完全丢失了主菜单,我必须以编程方式重新添加它,但我无法重新添加分隔符。 因此,经过一段时间的努力,我可以把一切都找回来。 这就是我再次将分隔符重新添加到菜单中所做的操作:
要使用 MenuStrip 或 ContextMenuStrip 执行此操作,只需将“DropDownItems”替换为“Items”。
就是这样。 我希望它有帮助...
I had an issue with one of my projects where I completely lost my main menu and I had to re-add it programatically, but I could not re-add the separators. So after trying for quite a while I could get it all back. This is what I did to re-add the separators to the menu again:
For doing this with a MenuStrip or ContextMenuStrip just replace "DropDownItems" with "Items".
That's it. I hope it helps...
脚步:
1.右键单击上下文菜单条带项目-> 插入-> 分隔符
或
a) 单击要放置水平分隔符的位置(ContextMenuStrip 的类型文本框),然后输入“-”(减号)
b) 输入
希望这对您有用:)
steps:
1. right click on contextmenuStrip items - > Insert -> Separator
OR
a) Click on (Type Text box for ContextMenuStrip) where you want to put the horizontal separator, then enter" - "(Minus sign)
b) Enter
hope this will find you useful :)
我喜欢用 - 而不是分隔符。 假设我想制作一个水平分隔符,我会做大约 30 个分隔符来创建一条长度为 30 的水平虚线。然后我将其启用属性设置为 false,这样就无法像垂直分隔符那样单击它。 就做| 然后您的每个项目的项目,您会注意到它将创建一条与每个项目匹配的垂直线。 [注意] 由于每个项目之间的间距,垂直线会出现虚线。
I like to do mine with - rather then a separator. So say i wanna make a horizontal separator i would do about 30 of them to create a horizontal dotted line with a length of 30. Then i would set its enabled property to false so it can't be clicked as for a vertical one. Just do | then your item for each item and you will notice it will create a vertical line matching up with each item. [Note] The vertical line will be dotted due to the spacing between each item.
就这么简单,
右键单击上下文菜单条图标。
然后选择插入,然后选择分隔符 |
It' so simple,
Right click on the Context menu strip icon.
then Select insert and after select Separator |
菜单条项目没有分隔符。
然而;
您可以选择要在其之间留有空格的项目,然后设置左边距或右边距值。 这也同样有效。
There are no separators for menu strip items.
However;
You can select the item you want a space between, and set the left or right margin value. This works just as well.
例如对于 3 然后选择示例 toolStripMenuItem1 并单击 DropDownItems“...”然后在新打开的窗口部分中“选择项目并添加到下面的列表”选择分隔符| 并添加它。
好锁
For Example For 3 Then Select the for example toolStripMenuItem1 and Click DropDownItems "..." Then in Section to New Opened Window "Select item and add to list below" Select Separator | And Add it.
Good Lock
由于某种原因,上述与设计师相关的答案似乎在 VS 2019 (16.8.4) 中对我不起作用。 缺少插入分隔符选项,并且在文本中使用“-”似乎不起作用。
我可以添加分隔符的唯一方法是在设计器中执行以下操作:
顶部菜单条上的人民币 -> 选择
Edit DropDownItems
这将弹出一个对话框,允许您添加分隔符(以及任何其他菜单项)。
For some reason none of the above designer related answers seemed to work for me in VS 2019 (16.8.4). Insert Separator option is missing and using "-" in the text does not seem to work.
The only way I could add a separator was to do the following in designer:
RMB on the top menu strip -> select
Edit DropDownItems
This brings up a dialogue box that allows you to add separators (as well as any other menu items).
只需将“-”添加到菜单条中所需的位置即可。
Just add "-" to the place you want in your menustrip.