Text button on toolbar
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.
Set ToolStripItem.DisplayStyle to Text :
var toolStripButton = new ToolStripButton();
toolStripButton.DisplayStyle = ToolStripItemDisplayStyle.Text;
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));
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.
精彩评论