C # winForm RichTextBox Each row displays a different color

 

 

/// <Summary>
/// Show log
/// </ Summary>
/// <param name = "MSG"> message </ param>
/// <param name = "Color"> display color </ param >
Private void ShowMsg (String MSG, Color Color)
{
IF (String.IsNullOrEmpty (MSG))
return;

if (txtLog.IsHandleCreated)
{
txtLog.BeginInvoke(new Action(() =>
{
txtLog.SelectionColor = color; // 设置输入字体颜色
txtLog.AppendText(DateTime.Now.ToString("[mm:ss] ") + msg + Environment.NewLine);

txtLog.Focus (); // get the focus
txtLog.Select (txtLog.TextLength, 0); // text cursor to the last
txtLog.ScrollToCaret (); // cursor to scroll
DoOutMessage (MSG,. 9);
})) ;
}
}

Guess you like

Origin www.cnblogs.com/boyxzhen/p/12446916.html