谁能告诉我如何获取 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 但如果我将鼠标悬停在笔上以获取子菜单红色和蓝色,此子菜单将显示在自动调整大小的条带上!
如何获取子菜单属性以便设置它的高度?