1

I've been trying and trying to get the standard C# toolstrip control to format button text as multiline, and so far I've had to admit defeat.

What I'm trying to achieve is text under the picture, and the text wrapping a fixed icon size, rather than extending the icon size to accommodate the text, I'm not sure if I can explain it any easier - at the minute, the program looks like the following:

Icon Image  
Icon Text - extending icon

whereas I actually want it to display as such:

Icon Image

Icon Text  
Wrapped  
Under Icon

I'm a bit stuck as to explain it any better than that, there's no multiline property on icons, and they don't accept the standard \n escape to force a newline.

I've got a horrid thought that I'm going to need to create a custom toolstripbutton class in order to do this, but I'm at a complete loss as to where to begin with that, so any help is graciously appreciated!

Thanks in advance for any assistance :)

Paul Sasik
  • 73,575
  • 18
  • 144
  • 180
T5Dave
  • 13
  • 1
  • 3

2 Answers2

3

You can programmatically set the Text property of the ToolStripButton like this:

toolStripButton1.Text = "Hello\nWorld!";

Run this in your form's constructor.

Of course you'd also set your ToolStripButton's ImageTextRelation property to ImageAboveText and its DisplayStyle to ImageAndText.

Jay Riggs
  • 51,115
  • 9
  • 133
  • 146
  • 1
    You should do it in the constructor so everything gets scaled properly on a machine with a different DPI setting. – Hans Passant Mar 31 '11 at 20:29
  • @Hans You're right - +1 for this [What setup code should go in Form Constructors versus Form Load event](http://stackoverflow.com/questions/2521322/what-setup-code-should-go-in-form-constructors-versus-form-load-event)? – Jay Riggs Mar 31 '11 at 20:32
  • Absolutely perfect, thanks gentlemen! I tried setting the property with a \n escape but it never occurred to try it programmatically! Also, thanks to Paul Sasik for correcting the formatting in my original post! – T5Dave Mar 31 '11 at 20:37
0

I used this code to display the text property in two lines;

  toolStripButton1.Text = "Hello" + Environment.NewLine + "World!";
juanchoelx
  • 258
  • 1
  • 5
  • 17