Question

How do I add a GlassButton to a ToolStrip using C#. My code is:

ToolStrip toolStripTaskBar = new ToolStrip();
GlassButton gBtn = new GlassButton();
ToolStripButton button = (ToolStripButton)gBtn;
toolStripTaskBar.Items.Add(button);

I'm getting the following exception:

Cannot convert type 'Glass.GlassButton' to 'System.Windows.Forms.ToolStripButton'

Any suggestions how can I achieve this?

Était-ce utile?

La solution

Use ToolStripControlHost instead of ToolStripButton to add your custom button to the ToolStrip:

ToolStrip toolStripTaskBar = new ToolStrip();
GlassButton gBtn = new GlassButton();
ToolStripControlHost button = new ToolStripControlHost(gBtn);
toolStripTaskBar.Items.Add(button);

Autres conseils

You're going to have to wrap your GlassButton is a class that bases ToolStripItem. The scope of issues you're going to run into with this is unknown and too broad for this forum.

The bottom line, a GlassButton is not, and does not base, ToolStripItem and that's why you're getting the error.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top