Pergunta

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?

Foi útil?

Solução

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

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top