我首先在一个richTextBox里设置好内容(包括格式、颜色),其中包括一些变量,比如[姓名],便于以后用值替换掉;然后保存到数据库的image字段。
然后在使用的时候读取出来,放入richTextBox中,字体格式完全一致。但是我现在想替换掉变量,值的格式完全和变量一致。比如一个人名字叫张三,那这两个字的格式应该完全和[姓名]一致。请问应该如何准确替换呢,希望能给出一些代码,非常感谢。
然后在使用的时候读取出来,放入richTextBox中,字体格式完全一致。但是我现在想替换掉变量,值的格式完全和变量一致。比如一个人名字叫张三,那这两个字的格式应该完全和[姓名]一致。请问应该如何准确替换呢,希望能给出一些代码,非常感谢。
请问应该如何替换呢?
不过这个应该算外部方法,最好是能直接修改rtf中的文字和格式,期待高手出现。
{
// Clear all text from the RichTextBox;
richTextBox1.Clear();
// Set the font for the opening text to a larger Arial font;
richTextBox1.SelectionFont = new Font("Arial", 16);
// Assign the introduction text to the RichTextBox control.
richTextBox1.SelectedText = "The following is a list of bulleted items:" + "\n";
// Set the Font for the first item to a smaller size Arial font.
richTextBox1.SelectionFont = new Font("Arial", 12);
// Specify that the following items are to be added to a bulleted list.
richTextBox1.SelectionBullet = true;
// Set the color of the item text.
richTextBox1.SelectionColor = Color.Red;
// Assign the text to the bulleted item.
richTextBox1.SelectedText = "Apples" + "\n";
// Apply same font since font settings do not carry to next line.
richTextBox1.SelectionFont = new Font("Arial", 12);
richTextBox1.SelectionColor = Color.Orange;
richTextBox1.SelectedText = "Oranges" + "\n";
richTextBox1.SelectionFont = new Font("Arial", 12);
richTextBox1.SelectionColor = Color.Purple;
richTextBox1.SelectedText = "Grapes" + "\n";
// End the bulleted list.
richTextBox1.SelectionBullet = false;
// Specify the font size and string for text displayed below bulleted list.
richTextBox1.SelectionFont = new Font("Arial", 16);
richTextBox1.SelectedText = "Bulleted Text Complete!";
}
但是我觉得最理想的还是能直接修改rtf来实现这些功能。
还是非常感谢您 ^^