Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RichTextBox Formatting tab stops.

Status
Not open for further replies.

mvanrijn

Programmer
Jun 23, 2002
19
GB
Hi,

How do I set the 3 tab stop positions within a RichTextBox?

I've been formatting text with a richtextbox control on a windows form. I have the basic format working, fonts, alignment ect... But I have been trying to add tab stops to the formatting. How do I do this. The tabs are inserted in the text, but I am trying to change the spacing between tabs.

Here is a sample of code, I've cut it and changed it from my code but it should give you the basic idea.

{
System.Windows.Forms.RichTextBox rtext;
string print_detail = null;

Font currFont = rtext.SelectionFont;
FontStyle newFontStyle;
float newFontsize;

// New Format
newFontStyle = FontStyle.Regular;
newFontsize = 8;

rtext.SelectionFont = new Font(currFont.FontFamily,newFontsize,newFontStyle);
rtext.SelectionIndent = 100;
// Fills in the string
print_detail = "Table name \t Table Owner \t Table Desc \t Other ";
if (print_detail != null)
{
rtext.AppendText(print_detail);
rtext.AppendText("\n\n");
}
}
I've been trying to use the RichTextBox.SelectionTabs but each time I try to assign the tab stops using this, it crashes at runtime.

int[] tabstops = {100,150,200};
rtext.SelectionTabs = tabstops;

Thanks for any help in advance
MJ
 
OK I've figured out what was wrong

Basically if there are no tabstops in the RichText Box you need to initialise SelectionTabs. Otherwise you get an array out of bounds error.

ie going back to my code

rtext.SelectionTabs = new int[3];
rtext.SelectionTabs = tabstops;

The 3 is the number of tabs you want to create it can be upto 32.
Tabstops is an array filled with the tab stop positions in pixels.

I'm glad I've sorted that out for myself. I hope this is useful to someone else.

Cheers
MJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top