C# ContextMenuStrip 子菜单属性
谁能告诉我如何获取 ContextMenuStrip 中子菜单的属性?
我知道我可以创建一个表单并将上下文菜单条拖放到其上。如果我然后将一些项目添加到条中:
列出项目
- 笔
- - 红色
- - 蓝色
- 标记
- - 绿色
- - 橙色
然后我编写以下代码:
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
this.contextMenuStrip1.AutoSize = false;
this.contextMenuStrip1.Height = 300;
this.contextMenuStrip1.Width = 150;
}
/// <summary>
/// Handles the MouseClick event of the Form1 control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
private void Form3_MouseClick_1(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Point pt = this.PointToScreen(e.Location);
this.contextMenuStrip1.Show(pt);
}
}
}
显示笔和标记的顶级菜单将位于非自动调整大小的条上 150 * 300 但如果我将鼠标悬停在“笔”上以获取子菜单“红色”和“蓝色”,该子菜单将显示在自动调整大小的条上!
如何获取子菜单属性以便设置其高度?
Can anyone tell me how to get at the properties for the submenu in a ContextMenuStrip?
I know I can create a form and drop a context menu strip onto it. If I then add some items to the strip:
List item
- Pens
- -- Red
- -- Blue
- Markers
- -- Green
- -- Orange
I then write the following code:
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
this.contextMenuStrip1.AutoSize = false;
this.contextMenuStrip1.Height = 300;
this.contextMenuStrip1.Width = 150;
}
/// <summary>
/// Handles the MouseClick event of the Form1 control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
private void Form3_MouseClick_1(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Point pt = this.PointToScreen(e.Location);
this.contextMenuStrip1.Show(pt);
}
}
}
The Top level menu showing Pens and Markers will be on a non autosized strip 150 * 300 but if i hover over Pens to get the sub menu, Red and Blue, this submenu will show up on a autosized strip!
How do I get at the sub menu properties so I can set it's height?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于您的问题
使用
Items
:对于
items[0]
的任何子项:For your question about
Use
Items
:and for any sub-itmes of
items[0]
: