using System.Drawing; using System.Windows.Forms; namespace UTIL { #region Расширенные методы RichTextBox public static class RichTextBoxExtensions { public static void AppendText(this RichTextBox box, string text, Color color) { if (box.InvokeRequired) { box.Invoke((MethodInvoker)(delegate { box.SelectionStart = box.TextLength; box.SelectionLength = 0; box.SelectionColor = color; box.AppendText(text); box.SelectionColor = box.ForeColor; box.ScrollToCaret(); })); } else { box.SelectionStart = box.TextLength; box.SelectionLength = 0; box.SelectionColor = color; box.AppendText(text); box.SelectionColor = box.ForeColor; box.ScrollToCaret(); } } public static void AppendText(this RichTextBox box, string text, Color bgcolor, Color fgcolor) { if (box.InvokeRequired) { box.Invoke((MethodInvoker)(delegate { box.SelectionStart = box.TextLength; box.SelectionLength = 0; box.SelectionColor = fgcolor; box.SelectionBackColor = bgcolor; box.AppendText(text); box.SelectionColor = box.ForeColor; box.SelectionBackColor = box.BackColor; box.ScrollToCaret(); })); } else { box.SelectionStart = box.TextLength; box.SelectionLength = 0; box.SelectionColor = fgcolor; box.SelectionBackColor = bgcolor; box.AppendText(text); box.SelectionColor = box.ForeColor; box.SelectionBackColor = box.BackColor; box.ScrollToCaret(); } } } #endregion }