How do you change the text color of a readonly TextBox?

Viewed 26548

I am writing a dictionary with c# and I'm using a textbox to show the definitions. Obviously, I need to set the ReadOnly property to true, but when I do that I'm unable to change the color of the text. Changing the Font however works fine. What should I do?

I'm using this code and setting the color works perfectly fine when the ReadOnly property is false, but doesn't change when it is true:

    private void button5_Click(object sender, EventArgs e)
    {
        FontDialog fd = new FontDialog();
        fd.ShowColor = true;
        if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            textBox3.Font = fd.Font;
            textBox3.ForeColor = fd.Color;
        }
    }
4 Answers

In VS 2017 this is not even needed.

In designer if you have set your ForeColor and BackColor as desired and want to switch ReadOnly on your TextBox to True

  • Change BackColor to any random color and compile
  • Change BackColor to your desired color and compile

Thanks to LarsTech suggestion I had to set the back color and then set it again

This is the method that worked for me:

    tb.BackColor = Color.Black
    tb.ForeColor = Color.Black
    tb.BackColor = Color.White
Related