zoukankan      html  css  js  c++  java
  • C# 输出带颜色文字,用于实时日志输出

     1      private void button1_Click(object sender, EventArgs e)  
     2         {  
     3           LogMessage("绿色");  
     4        LogError("红色");  
     5        LogWarning("粉色");  
     6         }  
     9 #region 日志记录、支持其他线程访问  
    10   
    11         public delegate void LogAppendDelegate(Color color, string text);  
    12   
    13         public void LogAppendMethod(Color color, string text)  
    14         {  
    15             if (!richTextBox1.ReadOnly)  
    16                 richTextBox1.ReadOnly = true;  
    17   
    18             richTextBox1.AppendText("
    ");  
    19             richTextBox1.SelectionColor = color;  
    20             richTextBox1.AppendText(text);  
    21         }  
    22   
    23         public void LogError(string text)  
    24         {  
    25             LogAppendDelegate la = new LogAppendDelegate(LogAppendMethod);  
    26             richTextBox1.Invoke(la, Color.Red, DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] ") + text);  
    27         }  
    28         public void LogWarning(string text)  
    29         {  
    30             LogAppendDelegate la = new LogAppendDelegate(LogAppendMethod);  
    31             richTextBox1.Invoke(la, Color.Violet, DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] ") + text);  
    32         }  
    33         public void LogMessage(string text)  
    34         {  
    35             LogAppendDelegate la = new LogAppendDelegate(LogAppendMethod);  
    36             richTextBox1.Invoke(la, Color.Green, DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] ") + text);  
    37         }  
    38          
    39 #endregion  

     如图显示:

  • 相关阅读:
    AcWing 204. 表达整数的奇怪方式 / Strange Way To Express Integers
    Codeforces Edu Round 67 A-C + E
    Codeforces Edu Round 66 A-E
    Codeforces Edu Round 65 A-E
    Codeforces Edu Round 64 A-D
    Codeforces Edu Round 63 A-E
    Codeforces Edu Round 62 A-E
    Codeforces Edu Round 61 A-C + F
    python 线程池和锁
    python 线程
  • 原文地址:https://www.cnblogs.com/xuliangxing/p/6548849.html
Copyright © 2011-2022 走看看