2

Such as a Label and a TextBox.

I tried:

class MyClass : ToolStripPanel
{
      //...
}

And the like. But then:

contextMenuStrip1.Items.Add(new MyClass());

shows an error:

...invalid arguments.

ispiro
  • 26,556
  • 38
  • 136
  • 291
  • No. It's not "totally incorrect". It's overloaded. – ispiro Dec 25 '12 at 20:34
  • You can add a ToolStripPanel control directly to your ContextMenuStrip, and then add controls to the ToolStripPanel - is that what you want to do? There isn't really a need to inherit directly from the ToolStripPanel class. – dash Dec 25 '12 at 20:34
  • @dash This: `contextMenuStrip1.Items.Add(new ToolStripPanel());` fails the same way. – ispiro Dec 25 '12 at 20:39
  • Sorry, my mistake - it's been a while since I've done this. You can use the ToolStripControlHost class - I can give you an example if you want? – dash Dec 25 '12 at 20:46

1 Answers1

13

You can use the ToolStripControlHost class to host any Windows Forms control on a ContextMenuStrip (or indeed any of the Strip controls)

For example, the following code will add a label to a context menu strip:

    Label newlabel = new Label();
    newlabel.Text = "Hello World";
    newlabel.Width = 300;
    ToolStripControlHost tsHost = new ToolStripControlHost(newlabel);

    contextMenuStrip1.Items.Add(tsHost);
dash
  • 89,546
  • 4
  • 51
  • 71