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