Title: Set RichTextBox tab stops in C#
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" +
"\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 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 the example to experiment with it and to see additional details.
|