0

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?

Community
  • 1
  • 1
AidanO
  • 868
  • 1
  • 11
  • 33

1 Answers1

0

For your question about

How do I get at the sub menu properties so I can tell it what height I want it!

Use Items:

ContextMenuStrip1.Items[0].Height=200;

and for any sub-itmes of items[0]:

foreach(ToolStripItem item in (ContextMenuStrip1.Items[0] as ToolStripDropDownItem).DropDownItems)
{
    item.AutoSize=false;
    item.Height=200;
}
Bolu
  • 8,696
  • 4
  • 38
  • 70
  • That won't do the trick for me. While it will cause the items to be bigger, and force the "containing menu" to be bigger it's not what I'm looking for. I've actually written a custom render to do some funky things with the items that will prevent the auto size from working so I wish to manually set the size of the containing menu. – AidanO Aug 08 '11 at 15:06
  • @AidanO, I'm confused with what you want to achieve. – Bolu Aug 08 '11 at 15:11
  • The top level items are held within a contextmenustrip that has a height and a width that can be set independant of the items. I wish to get at the object that holds the items that are not on the top level. – AidanO Aug 08 '11 at 15:24