Set RichTextBox tab stops in C#

[RichTextBox tab stops]

You can set different RichTextBox tab stops for different parts of a RichTextBox control’s text. This example uses the following code to set tabs for the whole control and then adds some text to it that includes tabs.

// Set the tabs and enter some text.
private void Form1_Load(object sender, EventArgs e)
    rchItems.SelectionTabs = new int[] { 80, 160, 240 };
    rchItems.AcceptsTab = true;

    rchItems.Text =
        "Breakfast\tLunch\tDinner\n" +
        "Coffee\tSoda\tWine\n" +
        "Bagel\tSandwich\tSalad\n" +
        "Fruit\tChips\tTofuburger\n" +

This code sets the control’s SelectionTabs property to an array of integers giving the tabs’ positions. If you want to set the tabs for only some of the control’s text, select that text before you set this property. In this example, the control doesn’t contain any text at this point so the tabs apply to all later text.

The code sets AcceptsTab to true so you can type tab characters into the control at run time without moving focus to the next control.

Download Example   Follow me on Twitter   RSS feed   Donate

This entry was posted in controls and tagged , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.