【发布时间】:2016-06-29 11:09:21
【问题描述】:
我使用了一个富文本框来在我的 WinForms 中显示日志。
使用的语言是 C#。
该软件用于插入银行分行的数据,在新分行启动后我想显示一个新颜色的文本。
我看到了链接Color different parts of a RichTextBox string并成功实现。
我的问题是我想添加新行而不是追加。也就是说,新行将显示在顶部。
我可以通过将代码更改为box.Text=DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") + ": " + text + box.Text来做到这一点
但整个文本的颜色正在改变。
这是用于追加的过程
box.SelectionStart = box.TextLength;
box.SelectionLength = 0;
box.SelectionColor = color;
box.AppendText(DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") + ": " + text);
box.SelectionColor = box.ForeColor;
这就是我所做的:
box.Text=DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") + ": " + text + box.text;
box.SelectionStart = 0;
box.SelectionLength = text.length;
box.SelectionColor = color;
但这不起作用。
【问题讨论】:
标签: c# winforms richtextbox