You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.1 KiB
63 lines
2.1 KiB
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 |
|
}
|
|
|