Reputation: 4012
I want to add a text button onto a WinForms toolbar (a standard button on a toolbar can contain an image only).
A textbox, a combobox can be easily added onto a toolbar but there is no option for a text button.
How can that be achieved?
UPD By 'text button' I mean the standard Windows button.
Upvotes: 4
Views: 4144
Reputation: 2537
Set ToolStripItem.DisplayStyle to Text :
var toolStripButton = new ToolStripButton();
toolStripButton.DisplayStyle = ToolStripItemDisplayStyle.Text;
Upvotes: 5
Reputation: 263067
You can use a ToolStripControlHost to embed any control in your toolstrip:
Button button = new Button();
button.Text = "Standard Windows Button";
yourToolStrip.Items.Add(new ToolStripControlHost(button));
Upvotes: 2
Reputation: 16162
I assume you mean by text button
a button that not only contain image but also a text. So:
ToolBar toolbar = new ToolBar();
Button button = new Button();
button.Text = "Hi!";
button.Image = Image.FromFile("Your image path");//or from resource..
toolbar.Add(button);
this.Controls.Add(toolbar);
Edit: Since you mean ToolStrip
you can do:
string text = "Hi";
Image image = Image.FromFile("Your image path");
ToolStripButton toolButton = new ToolStripButton(text, image);
toolButton.TextImageRelation = TextImageRelation.Overlay;//or what ever you want to
toolStrip1.Items.Add(toolButton);
Edit:
looks like a menu entry (a label which is highlighted when the mouse is over), not the standard button.
Unfortunately that what Microsoft provided. if you don't like it inherit the ToolStripItem
and design your own.
Also note that you can use toolButton.BackgroundImage
but it also will not give you the same effect that the ordinary Button
will do.
Upvotes: 2