【发布时间】:2017-01-31 14:33:00
【问题描述】:
foreach(string line in lines)
{
richTextBox1.AppendText(line);
RichTextBoxExtensions.AppendText(richTextBox1, "Ready: ", Color.Red);
}
如果行是
“你好世界”
所以我想要的是在RichTextBox1 的第一行:
准备好你好世界
其中 Ready 仅显示为红色 Ready。
在下一行再次
准备好你好
Again Ready 是红色的,但是你好,它的原始颜色没有改变。
但是我得到的是混乱的世界 Ready 被添加到最后一行之后,它不是仅在第一行中的红色。
还在RichTextBox 中将所有行和Ready 添加为文本块而不是行。
我想在运行程序时在RichTextBox 中看到的是行:
准备好了:世界你好
准备好了:你好你好
准备好了:这是一条线
准备好了:大家好
只有
准备好了:
红色
public class RichTextBoxExtensions
{
public static void AppendText(RichTextBox box, string text, Color color)
{
box.SelectionStart = box.TextLength;
box.SelectionLength = 0;
box.SelectionColor = color;
box.AppendText(text);
box.SelectionColor = box.ForeColor;
}
public static void UpdateText(RichTextBox box, string find, string replace, Color? color)
{
box.SelectionStart = box.Find(find, RichTextBoxFinds.Reverse);
box.SelectionLength = find.Length;
box.SelectionColor = color ?? box.SelectionColor;
box.SelectedText = replace;
}
}
【问题讨论】:
标签: c# .net winforms richtextbox