Display label text with line breaks in c#

后端 未结 8 570
面向向阳花
面向向阳花 2020-12-05 09:28

Is it possible to display the label text with line breaks exactly as per the image

\"enter

相关标签:
8条回答
  • 2020-12-05 10:19

    You can use <br /> for Line Breaks, and &nbsp; for white space.

    string s = "First line <br /> Second line";
    

    Output:

    First line
    Second line
    

    For more info refer to this: Line break in Label

    0 讨论(0)
  • 2020-12-05 10:22

    You may append HTML <br /> in between your lines. Something like:

    MyLabel.Text = "SomeText asdfa asd fas df asdf" + "<br />" + "Some more text";
    

    With StringBuilder you can try:

    StringBuilder sb = new StringBuilder();
    sb.AppendLine("Some text with line one");
    sb.AppendLine("Some mpre text with line two");
    MyLabel.Text = sb.ToString().Replace(Environment.NewLine, "<br />");
    
    0 讨论(0)
提交回复
热议问题