0

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

如何获取子菜单属性以便设置它的高度?

4

1 回答 1

0

关于你的问题

我如何获得子菜单属性,这样我就可以告诉它我想要什么高度!

使用Items

ContextMenuStrip1.Items[0].Height=200;

和任何子项目items[0]

foreach(ToolStripItem item in (ContextMenuStrip1.Items[0] as ToolStripDropDownItem).DropDownItems)
{
    item.AutoSize=false;
    item.Height=200;
}
于 2011-08-08T14:50:02.873 回答