GER
GER

Reputation: 2032

ToolStripTextBox image is not appearing

I am using WindowsForms and I am trying to put a Textbox into my main menu and add an Image. However I cannot get the image to appear. What am I missing here.

txtRequestEdit.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
txtRequestEdit.Image = Properties.Resources.Wrench16 'This is a valid image.

txtRequestEdit is a System.Windows.Forms.ToolStripTextBox


EDIT- Here is an image of the menu. The item at the bottom of this menu is the txtRequestEdit control.
enter image description here

Upvotes: 1

Views: 1041

Answers (2)

SSoper97470
SSoper97470

Reputation: 61

For others falling looking for the correct answer, it is to create a class inherited from ToolStripTextBox and override its Image property and override the Paint method. See this topic

Upvotes: 1

Alireza
Alireza

Reputation: 5056

Strangely the no matter how you apply the image, it won't show on ToolStripTextBox. I think this is a bug because I found nothing about this behavior in the documents or on the web.

I will try doing this with a hack like owner-drawing the item or something else and will put the wrong answer here so the next person with this issue avoids this wrong path.

This is wrong:

Apparently the Image property "supports the .NET Framework infrastructure and is not intended to be used directly from your code.", so if (as you say) everything's OK and you've checked the image itself to be valid, using ImageList and ImageIndex may solve the problem (assuming the item lies inside a MenuStrip named menuStrip1:

txtRequestEdit.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
menuStrip1.ImageList = New ImageList()
menuStrip1.ImageList.Images.Add(Properties.Resources.Wrench16)
txtRequestEdit.ImageIndex = 0

Upvotes: 1

Related Questions