Skip to content

Instantly share code, notes, and snippets.

@shadowfox
Created June 21, 2013 07:29
Show Gist options
  • Save shadowfox/5829513 to your computer and use it in GitHub Desktop.
Save shadowfox/5829513 to your computer and use it in GitHub Desktop.
using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Utilities
{
/// <summary>
/// Extensions for System.Windows.Forms.RichTextBox
/// </summary>
public static class RichTextBoxExtensions
{
/// <summary>
/// Appends colored text to the textbox
/// </summary>
/// <param name="textBox">The rich text box</param>
/// <param name="text">The text to append</param>
/// <param name="color">The color of the text</param>
public static void AppendText(this RichTextBox textBox, string text, Color color)
{
textBox.SelectionStart = textBox.TextLength;
textBox.SelectionLength = 0;
textBox.SelectionColor = color;
textBox.AppendText(text);
textBox.SelectionColor = textBox.ForeColor;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment