RichTextbox tabStops not working

fguihen

Junior Contributor
Joined
Nov 10, 2003
Messages
248
Location
Eire
im adding text to a richTextBox through code. like so:

Code:
myRichTextBoxEx.SelectedText = "The following is a list of  fintans test:"+ "\n" ;

i want to be able to set tabs for my text but i cant get it done.
heres what ive tried:

Code:
int[] tabs = {100,300,600,900};

this.myRichTextBoxEx.AcceptsTab = true;

this.myRichTextBoxEx.SelectionTabs = tabs;

myRichTextBoxEx.SelectionStart = tabs[0];
			
myRichTextBoxEx.SelectedText = "The following is a list of  fintans test:"+ "\n" ;

it has absolutely no effect on the position of my text in the text box. actually, when i try to assign tabs[0] to SelectionStart, SelectionStart is always left at 0,no matter how i try to assign a value to it. what am i doing wrong?
 
Tabs are just a formatting tool. You can't treat them like cells in a table (if that is what you are trying to do). When the RTF box encounters a tab character, it advances the location of text output to the next tab. You are setting tab locations correctly, but to use them, you need to insert tab characters (i.e. in the string "Before Tab\tAfter Tab: the "\t" is interpreted as a tab character).

If you want to move the cursor to the first tab in the first line of a RTF box, you could do this:
C#:
char Tab = '\t';
int TabOffset = myRichTextBoxEx.Text.IndexOf(Tab);
myRichTextBoxEx.SelectionStart = TabOffset;
 
thank you. its been bothering me a while now. thanks for explaining. i was looking at it the wrong way completely.
 
Back
Top