我想將格式化文本和表格添加到richTextBox。richTextBox - 添加文本和表格
爲此,我使用這些代碼:
文字:
richTextBox1.SelectionFont = new Font("Maiandra GD", 30, FontStyle.Bold);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectionIndent = 0;
richTextBox1.AppendText("text text text");
而且表:
StringBuilder tableRtf = new StringBuilder();
tableRtf.Append(@"{\rtf1\fbidis\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}");
for (int j = 0; j <5; j++)
{
tableRtf.Append(@"\trowd");
tableRtf.Append(@"\cellx2500" + " ghhghgjghjghjhggjh");
tableRtf.Append(@"\intbl\cell");
tableRtf.Append(@"\cellx10000\intbl\cel");
tableRtf.Append(" " + "sdfsdfs" + @"\intbl\clmrg\cell\row");
}
tableRtf.Append(@"\pard");
tableRtf.Append(@"}");
richTextBox1.Rtf=tableRtf.ToString();
但
richTextBox1.Rtf=tableRtf.ToString();
殺死了以前的內容。
我該如何使它們兼容?
1)添加格式化文本到RichTextBox的這樣:
richTextBox1.SelectionFont = new Font("Maiandra GD", 30, FontStyle.Bold);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.AppendText("text text text");
它非常可讀的,我可以很容易地修改
,因爲我想要兩個的事情,是不是重複。
2)我想添加表格。
所以結構:
文字文字文字文字文字文字 文字文字文字文字
| TABLE |
文字文字文字文字文字文字 文字文字文字文字文字 文字文字文字文字
| TABLE |
等
但我不知道我怎麼能申請表格,而不會丟失以前的內容?
的[字符串添加到在C#一個RichTextBox]可能的複製(https://stackoverflow.com/questions/6485156/adding-strings-to-a-richtextbox-in-c-sharp) – mjwills
你想做richTextBox1.Rtf = tableRtf.Rtf; ? 調用.ToString只會給你一個系統字符串,顯然不包含任何格式。 –
@Joe_DM但是格式化顯然是在字符串 –