using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace gitCompare
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
this.richTextBox1.Text += "This is some text. ";
this.richTextBox1.SelectionColor = Color.CadetBlue;
this.richTextBox1.Text += "This is some text. ";

richTextBox1.SelectionStart = 5;
richTextBox1.SelectionLength = 10;
richTextBox1.SelectionColor = Color.CadetBlue;

this.resetCursorSelectionColor();
}

private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Text += textBox1.Text;
richTextBox1.SelectionStart = richTextBox1.Text.Length
- textBox1.Text.Length;
richTextBox1.SelectionLength = textBox1.Text.Length;
richTextBox1.SelectionColor = Color.Crimson;

this.resetCursorSelectionColor();
}

public void resetCursorSelectionColor()
{
richTextBox1.SelectionStart = richTextBox1.Text.Length;
richTextBox1.SelectionColor = Color.Black;
// still writes crimson after click.

richTextBox1.SelectionStart = 0;
richTextBox1.SelectionLength = 0;
richTextBox1.SelectionColor = Color.Black;

}

}
}

Labels: ,