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.
 
 

66 lines
1.6 KiB

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Extensions
{
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();
}
}
}
}