Modifying default tab size in RichTextBox

后端 未结 5 763
北海茫月
北海茫月 2020-12-11 01:07

Is there any way to change the default tab size in a .NET RichTextBox? It currently seems to be set to the equivalent of 8 spaces which is kinda large for my taste.

5条回答
  •  生来不讨喜
    2020-12-11 01:21

    You can set it by setting the SelectionTabs property.

    private void Form1_Load(object sender, EventArgs e)
    {
        richTextBox1.SelectionTabs = new int[] { 100, 200, 300, 400 };
    }
    

    UPDATE:
    The sequence matters....

    If you set the tabs prior to the control's text being initialized, then you don't have to select the text prior to setting the tabs.

    For example, in the above code, this will keep the text with the original 8 spaces tab stops:

    richTextBox1.Text = "\t1\t2\t3\t4";
    richTextBox1.SelectionTabs = new int[] { 100, 200, 300, 400 };
    

    But this will use the new ones:

    richTextBox1.SelectionTabs = new int[] { 100, 200, 300, 400 };
    richTextBox1.Text = "\t1\t2\t3\t4";
    

提交回复
热议问题