There is something odd about the ForeColor property of a read only System.Windows.Form.TextBox which I haven't seen documented, although I haven't looked very hard.
I've noticed that a foreground colour change only takes effect after the background colour has been changed once. After that any subsequent foreground changes take place immediately.
My little test app:
using System;
using System.Drawing;
using System.Windows.Forms;
public partial class Form1 : Form {
private readonly Color[] rainbow = new Color[] {
Color.Red,
Color.Orange,
Color.Yellow,
Color.Green,
Color.Blue,
Color.Indigo,
Color.Violet
};
private Int32 foreIdx, backIdx;
public Form1() {
InitializeComponent();
backIdx = rainbow.Length - 1;
NormalTextBox.Text = "Standard text box";
ReadOnlyTextBox.Text = "Read only text box";
}
private void ForeColBtn_Click(object sender, EventArgs e) {
NormalTextBox.ForeColor = rainbow[foreIdx];
ReadOnlyTextBox.ForeColor = rainbow[foreIdx];
foreIdx = ++foreIdx % rainbow.Length;
}
private void BackColBtn_Click(object sender, EventArgs e) {
NormalTextBox.BackColor = rainbow[backIdx];
ReadOnlyTextBox.BackColor = rainbow[backIdx];
backIdx = ++backIdx % rainbow.Length;
}
}
Have fun,
Alan.