[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Set RichTextBox tab stops in C#

[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.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.