Carriage Return in WinForms Label?

  • Thread starter Thread starter Cool Guy
  • Start date Start date
C

Cool Guy

Is it possible to insert a carriage return in a WinForms Label's Text with
the VS.NET WinForms Designer?

(Including '\n' doesn't work -- that gets converted to '\\n'.)
 
Cool said:
Is it possible to insert a carriage return in a WinForms Label's Text with
the VS.NET WinForms Designer?

(Including '\n' doesn't work -- that gets converted to '\\n'.)

I think it's not possible to do this by editing the text in the property
grid. But you can (carefully!) edit the designer generated code and change
the text. One possibility is to insert \n's, like this:

this.label.Text = "Text\nSecond line";

The other is to use verbatim literals like this:

this.label.Text = @"Text
Second line";

In the latter case, be sure to break the line in the place where you want
the linebreak!

In both cases, be aware that if you change the text in the property grid
afterwards, the designer will lose your manual changes. You're fine as
long as you don't make any changes to the text.


Oliver Sturm
 
Back
Top