locked
Indent in a Label? RRS feed

  • Question

  • User390853 posted

    I have a label may have one or 2 or 3 lines.how to make some indent in the first line?

    Tuesday, March 10, 2020 1:29 PM

Answers

  • User382871 posted

    Try the following code which could help add the indent to the string. And you can specify the space size.

    Check the code: ``` public MainPage() { InitializeComponent();

    label.Text = Indent(label.Text, 5);
    

    }

    string Indent(string value, int size) { var strArray = value.Split('\n'); var sb = new StringBuilder(); foreach (var s in strArray) sb.Append(new string(' ', size)).Append(s); return sb.ToString(); } ```

    Refer to: https://stackoverflow.com/a/46030323/11083277

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, March 11, 2020 2:04 AM