I would like to make a program where you can type in a richTextBox and then change the color.
So I tried this.
private void redFontColor_Click_1(object sender, EventArgs e)
{
richTxtBox.FrontColor = Color.Red;
}
But when I click the redFontColor button all the text in the richTextbox changes to red. So I tried to change the the color of each character individually.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Color currentColor = Color.Black;
private void redFontColor_Click_1(object sender, EventArgs e)
{
currentColor = Color.Red;
}
private void richTxtBox_TextChanged(object sender, EventArgs e)
{
if (textBox.SelectionStart != 0)
{
richTextBox.Select(textBox.SelectionStart - 1, 1);
richTextBox.SelectionColor = currentColor;
}
}
}
But when I now type something the color will change but when you enter a character it will be selected like this:
How could I make this work so the char isn't selected each time I type something? Or do I have to search for another method to do this?