Set tab stops in a RichTextBox control in C#

The RichTextBox control can set different tabs for different parts of its 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" +
"\tCookie\tVeggies";
}

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 have 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 the next control.

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.