繁体   English   中英

C#ContextMenuStrip子菜单属性

[英]C# ContextMenuStrip sub menu properties

谁能告诉我如何在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);
        }
    }
}

显示Pens and Markers的顶层菜单将位于非自动调整大小的条带150 * 300上,但是如果我将鼠标悬停在Pens上以获取红色和蓝色子菜单,则此子菜单将显示在自动调整大小的条带上!

如何获得子菜单属性,以便设置其高度?

关于您的问题

如何获得子菜单属性,以便告诉我我想要的高度!

使用Items

ContextMenuStrip1.Items[0].Height=200;

以及项目的任何子项目items[0]

foreach(ToolStripItem item in (ContextMenuStrip1.Items[0] as ToolStripDropDownItem).DropDownItems)
{
    item.AutoSize=false;
    item.Height=200;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM