-4

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?

Castrohenge
  • 8,525
  • 5
  • 39
  • 66
SK.
  • 4,174
  • 4
  • 30
  • 48
  • What is the problem with above code – Microsoft DN Jul 16 '13 at 11:43
  • @MicrosoftDJ cannot convert type 'Glass.GlassButton' to 'System.Windows.Forms.ToolStripButton' – SK. Jul 16 '13 at 11:47
  • 3
    So, what is this Glass.GlassButton? Your own class, a third party class? If it's not a ToolStripButton, how do you expect to add it as if it were? – Panagiotis Kanavos Jul 16 '13 at 11:51
  • 3
    Whatever your GlassButton is if its not derived from a ToolStripItem it can't be on a ToolStrip. – Ralf Jul 16 '13 at 11:52
  • Glass.GlassButton is third party class. I am using it to generate Glass Button. Now I want to add this button on toolstrip. – SK. Jul 16 '13 at 11:54
  • Skinning is done by the ToolStrip not the Items on the ToolStrip. So if you want a certain ToolStrip Look create a ToolStripRenderer thats will provide that look. – Ralf Jul 16 '13 at 12:06

2 Answers2

3

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);
Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
0

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.

Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232