I dynamically create multiple textboxes for showing information to the user. Now I want to set the back- and forecolor of some textboxes if a statement is true.
All this works just fine, untill I disable the textbox, now the forecolor "resets" to the standart color instead of showing my desired one.
DataTable dt = [some data]
//Col 0: ID
//Col 1: some text
//Col 2: date
for (int i = 0; i < dt.Rows.Count; i++)
{
DateTime d = (DateTime) dt.Rows[i].ItemArray[2];
TextBox txt = new TextBox();
txt.Multiline = true;
txt.Font = tb_Aufloesung.Font;
txt.Text = dt.Rows[i].ItemArray[1].ToString() + "\n" + d.ToString(@"dd.MM.yyyy");
txt.Size = new Size((TextRenderer.MeasureText(dt.Rows[i].ItemArray[1].ToString(), txt.Font).Width) + 10, 34);
txt.Location = new Point(43, 3 + split.Panel2.Controls.Count / 2 * 40);
if(d <= DateTime.Now) {
txt.BackColor = Color.Red;
txt.ForeColor = Color.White;
}
//txt.Enabled = false;
split.Panel2.Controls.Add(txt);
}
This is how the Textboxes look when I use the code above with :
- comment the line ->
//txt.Enabled = false;
- uncomment the line ->
txt.Enabled = false;
I have no idea why in the second case, the forecolor of the red textbox is not white as it should be. Anyone any idea?