How to 'align' text in RichTextBox C#?

前端 未结 5 652
天命终不由人
天命终不由人 2020-12-17 16:27

How do I align the text in a RichTextBox?

\"RTB\"

Basically, the RTB contains:

\"--testing\"

相关标签:
5条回答
  • 2020-12-17 17:11

    You would have to change the font to a monospaced font, like Courier. This behavior you're showing is standard with most fonts, as not all characters are the same width.

    0 讨论(0)
  • 2020-12-17 17:17

    Unless it is very necessary for you to use a rich textbox, you can simply use a textbox and choose alignment as

    textbox.TextAlign = HorizontalAlignment.Center;/*could be left, right or center*/
    
    0 讨论(0)
  • 2020-12-17 17:17
    RichTextBox1.SelectionAlignment = HorizontalAlignment.Center;
    

    or

    GetRichTextBox().SelectionAlignment = HorizontalAlignment.Center;
    

    for multiple pages.

    0 讨论(0)
  • 2020-12-17 17:30
    richTextBox1.SelectAll();
    richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
    richTextBox1.DeselectAll();
    
    0 讨论(0)
  • 2020-12-17 17:31

    You want to use the RichTextBox.SelectionAlignment property.

    For instance if you want the whole textbox centered, then you would do:

    richTextBox1.SelectAll();
    richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
    

    If you want only part of the textbox with a certain alignment, then use the RichTextBox.Select() routine to select the text, then set the SelectionAlignment property.

    0 讨论(0)
提交回复
热议问题