Domanda

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?

È stato utile?

Soluzione

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);

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top