View Single Post
Old 03-05-2009, 12:48 PM   #5 (permalink)
BobLewiston
 
Junior Techie

Join Date: Nov 2008

Posts: 91

BobLewiston is on a distinguished road

Default Re: how to change WinForm controls' text color programatically?

jaeusm:

Sorry, what I meant was:
Code:
using System; 
using System.Windows.Forms; 
  
namespace ChangeTextColor
{ 
    public partial class TestForm : Form
    { 
        public TestForm () 
        { 
            InitializeComponent (); 
            textBox1.Text = "This is the original text."; 
        } 
  
        private void btn_Click (object sender, EventArgs e) 
        { 
            textBox1.Text = "Now the text is red."; 
            textBox1.ForeColor = System.Drawing.Color.Red; 
        } 
    } 
}
The "text field of the control" I was referring to is textBox1.Text.

Anyway, it turns out that changing (or just reassigning an unchanged value to) the TextBox's BackColor property when also changing the ForeColor property somehow magically makes it work; don't ask me why.
BobLewiston is offline