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?

有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top