how to make what SelectionIndent does in tabs
-
Could I have an example how to make what richTextBox1.SelectionIndent does but measuring in tabs instead of pixels ? (I want to insert tabs in front of certain lines)
Tabs are characters. If you need to set a "tab" as Word denotes it, the
RichTextBox.SelectIndent
is the correct way. This changes the indentation of a paragraph but does not use a tab character, for changes in that paragraph would require a fairly complex algorithm to go and reposition tab characters. What you should do is get theFont
of the currently selected paragraph (usingRichTextBox.SelectionFont
), the do something like this:Graphics g = CreateGraphics();
SizeF size = g.MeasureString("\t", richTextBox1.SelectionFont);
int indentation = (int)size.Width;
richTextBox1.SelectionIndent = indentation;This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]
-
Tabs are characters. If you need to set a "tab" as Word denotes it, the
RichTextBox.SelectIndent
is the correct way. This changes the indentation of a paragraph but does not use a tab character, for changes in that paragraph would require a fairly complex algorithm to go and reposition tab characters. What you should do is get theFont
of the currently selected paragraph (usingRichTextBox.SelectionFont
), the do something like this:Graphics g = CreateGraphics();
SizeF size = g.MeasureString("\t", richTextBox1.SelectionFont);
int indentation = (int)size.Width;
richTextBox1.SelectionIndent = indentation;This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]