当前位置:编程学习 > C#/ASP.NET >>

C# richTextBox显示不同颜色文字

view plaincopy to clipboardPRint?
#region 日志记录、支持其他线程访问  
        public delegate void LogAppendDelegate(Color color, string text);  
        /// <summary>  
        /// 追加显示文本  
        /// </summary>  
        /// <param name="color">文本颜色</param>  
        /// <param name="text">显示文本</param>  
        public void LogAppend(Color color, string text)  
        {  
            richTextBoxRemote.AppendText(" ");  
            richTextBoxRemote.SelectionColor = color;  
            richTextBoxRemote.AppendText(text);  
        }  
        /// <summary>  
        /// 显示错误日志  
        /// </summary>  
        /// <param name="text"></param>  
        public void LogError(string text)  
        {  
            LogAppendDelegate la = new LogAppendDelegate(LogAppend);  
            richTextBoxRemote.Invoke(la, Color.Red, DateTime.Now.ToString("HH:mm:ss ") + text);  
        }  
        /// <summary>  
        /// 显示警告信息  
        /// </summary>  
        /// <param name="text"></param>  
        public void LogWarning(string text)  
        {  
            LogAppendDelegate la = new LogAppendDelegate(LogAppend);  
            richTextBoxRemote.Invoke(la, Color.Violet, DateTime.Now.ToString("HH:mm:ss ") + text);  
        }  
        /// <summary>  
        /// 显示信息  
        /// </summary>  
        /// <param name="text"></param>  
        public void LogMessage(string text)  
        {  
            LogAppendDelegate la = new LogAppendDelegate(LogAppend);  
            richTextBoxRemote.Invoke(la, Color.Black, DateTime.Now.ToString("HH:mm:ss ") + text);  
        } 
        #endregion

补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,