Reputation: 37
I have below text in richTextBox control.
i want to format text like below text
Upvotes: 0
Views: 406
Reputation: 8654
The RTF box can help you here, the only help using RTF will be using a table as Kosala mentioned.
You may use string operations for that:
int equalPos = 20;
for (int l = 0; l < rtfBox.Lines.Length; l++) {
int i = rtfBox.lines[i].IndexOf('=');
int n = equalPos - i;
if ((i >= 0) && (n > 0)) {
rtfBox.lines[i] = rtfBox.lines[i].Insert(i, new string(' ', n));
}
}
Wrote this from head, so please check for errors.
EDIT:
Ok, here's another one:
for (int l = 0; l < rtfBox.Lines.Length; l++) {
int i = rtfBox.lines[i].IndexOf('=');
if (i >= 0) {
rtfBox.lines[i] = rtfBox.lines[i].Insert(i, "\t");
}
}
rtfBox.SelectAll();
rtfBox.SelectionTabs = new int[] { 100 }; // Find a value big enough!
Upvotes: 1
Reputation: 2143
This is what I would do.(These are manual steps.. :)
1).Open MSWord.
2).Create a table; 2 columns and 5 rows (this is for your text)
3). put the text that you wanted to format in to correct cells of the table
4). Save Word Doc as a rtf file.
5). Open rtf file in notepad(notepad++ is better)
There it is.. Now you can find how it is formatted. Now it should not be hard for you to do it in C#. Good luck.
Upvotes: 0