我想将格式化文本和表格添加到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但是格式化显然是在字符串 –