This article example describes how C# displays different colors of text in RichTextBox. Share it for your reference. The specific implementation method is as follows:
#region logging, support other thread accesspublic delegate void LogAppendDelegate(Color color, string text); /// <summary> /// Append text/// </summary> /// <param name="color">Text color</param>/// <param name="text">Show text</param>public void LogAppend(Color color, string text) { ("\n"); = color; (text); } /// <summary> /// Display error log/// </summary> /// <param name="text"></param> public void LogError(string text) { LogAppendDelegate la = new LogAppendDelegate(LogAppend); (la, , ("HH:mm:ss ") + text); } /// <summary> /// Show warning message/// </summary> /// <param name="text"></param> public void LogWarning(string text) { LogAppendDelegate la = new LogAppendDelegate(LogAppend); (la, , ("HH:mm:ss ") + text); } /// <summary> /// Show information/// </summary> /// <param name="text"></param> public void LogMessage(string text) { LogAppendDelegate la = new LogAppendDelegate(LogAppend); (la, , ("HH:mm:ss ") + text); } #endregion
I hope this article will be helpful to everyone's C# programming.