How to create a table in RichTextBox ? You need to create a 2x1 table by clicking on Button , but if you press Enter (as in Word), one more line is added, and if you press Enter twice, the table closes and just continue to write text.
- There are no built-in tools for this, you will have to program everything yourself. - VladD
- Somewhere saw that it is possible to interpose ready tables from Word. Like a Word file with a table in a folder with the project is placed and a link to it. So it is possible? - Fanning
- It seems to be yes, RichTextBox supports RTF as an input format. - VladD
|
1 answer
Guided by this answer, you can do so.
We define the table procurement with one row and two cells:
string table = @"\trowd\cellx1000\cellx2000\intbl \cell\intbl \cell\row"; Code to add a table to the RichTextBox :
int index = richTextBox.Rtf.LastIndexOf("}"); richTextBox.Rtf = richTextBox.Rtf.Substring(0, index) + table + "}"; |