private delegate void Refresh_CallBack(Color color,string text);
private void ControlsRefresh(Color color, string text)
{
if (this.richTextBox1.InvokeRequired)
{
Refresh_CallBack d = new Refresh_CallBack(ControlsRefresh);
this.Invoke(d, new object[] { color, text });
}
else
{
lock (richTextBox1)
{
richTextBox1.AppendText(string.Empty);
richTextBox1.SelectionColor = color;
richTextBox1.AppendText(DateTime.Now.ToString("HH:mm:ss "));
richTextBox1.AppendText(text);
richTextBox1.AppendText("\n");
//设定光标所在位置
richTextBox1.SelectionStart = richTextBox1.TextLength;
//滚动到当前光标处
richTextBox1.ScrollToCaret();
}
}
}