Toolbar text button

I want to add a text button to the WinForms toolbar (the standard toolbar button can only contain an image).

The text box combobox can be easily added to the toolbar, but there is no text button.

How can this be achieved?

UPD By "text button" I mean the standard Windows button.

+4
source share
3 answers

You can use ToolStripControlHost to embed any control in your toolbar:

Button button = new Button(); button.Text = "Standard Windows Button"; yourToolStrip.Items.Add(new ToolStripControlHost(button)); 
+2
source

Set ToolStripItem.DisplayStyle to Text :

 var toolStripButton = new ToolStripButton(); toolStripButton.DisplayStyle = ToolStripItemDisplayStyle.Text; 
+3
source

I assume that you mean a text button button that contains not only the image, but also the 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:

It looks like a menu item (a shortcut that is highlighted when the mouse is finished), and not a standard button.

Unfortunately, what Microsoft provided. if you don't like it, inherit ToolStripItem and create your own.

Also note that you can use toolButton.BackgroundImage , but it also will not give you the same effect as a regular Button .

+2
source

All Articles