C#富文本框样式
问题描述:
我有一些来自DB的字符串(段落)。我需要给每个字符串一个单独的格式,例如颜色,粗体和斜体等。问题是我只能使用单个Rich文本框。
I have some strings(paragraphs) coming from DB. I need to give each of the string a separate formatting like coloring, bold and italic etc. Problem is that I am restricted to use a single Rich text box.
什么是解决我的问题?
谢谢
答
对于每个字符串您要对其应用样式,请选择字符串,然后应用所需的样式。像这样:
For each string you want to apply style to it, select the string and then apply the desired style. like:
richTextBox1.Text = "Hi this is a string";
richTextBox1.Select(0, 2);//selects Hi
richTextBox1.SelectionColor = Color.Red;//make its color red
richTextBox1.SelectionFont = new Font("Arial", 15, FontStyle.Bold); apply arial font to it and make it bold