C# winForm RichTextBox 每行顯示不同顏色


 

 

/// <summary>
/// 顯示日志
/// </summary>
/// <param name="msg">信息</param>
/// <param name="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(); // 獲取焦點
txtLog.Select(txtLog.TextLength, 0); // 光標定位到文本最后
txtLog.ScrollToCaret(); // 滾動到光標處
DoOutMessage(msg, 9);
}));
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM