color

06/15/2010 18:43 xStylo#1
Ive used this code for textbox, but it dont change the color to new color.
When it changed once, then it can't change again.
Anyone got a solution?
Code:
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (textBox1.Text == "Red")
            {
                textBox1.ForeColor = Color.Red;
            }
            if (textBox1.Text == " Blue")
            {
                textBox1.ForeColor = Color.Blue;
            }
        }
06/15/2010 18:51 Nullable#2
Code:
            if (textBox1.Text == "Red")
            {
                textBox1.ForeColor = Color.Red;
            }
            if (textBox1.Text == " Blue")
            {
                textBox1.ForeColor = Color.Blue;
            }
change to
Code:
            if (textBox1.Text == "Red")
            {
                textBox1.ForeColor = Color.Red;
            }
            if (textBox1.Text == "Blue")
            {
                textBox1.ForeColor = Color.Blue;
            }
Next time check for extra spaces that you might add by mistake before starting a new thread..
06/15/2010 19:19 xStylo#3
It was supposed to change color when i write Blue after Red.
But it don't do.
I have to remove all text and write Blue.
Any clue? :D
06/16/2010 17:19 s.bat#4
Quote:
Originally Posted by xStylo View Post
It was supposed to change color when i write Blue after Red.
But it don't do.
I have to remove all text and write Blue.
Any clue? :D
This is a general C# programming question that has nothing to do with CO2.

In the future, you should provide detailed instructions on what you're trying to accomplish before we waste our time solving your simple problems which could have been fixed by searching Google for certain keywords.

You should have known that the equality operator used on a string tests the entire contents of that string, so of course you won't get blue text if you're looking for the text they wrote after everything else. You need to start from the beginning, and learn C# again, IMHO.

If you want to test is a string ends with another string, then take a look at the [Only registered and activated users can see links. Click Here To Register...] for a possible solution to your problem.
06/16/2010 19:07 xStylo#5
I never worked alot with forms application.
Most console and xml.
06/18/2010 08:29 Ian*#6
Just do

Code:
public void GetColor()
{	
	if (textBox1.Text == "Red")
	{
		textBox1.ForeColor = Color.Red;
	}
	else if (textBox1.Text == "Red Blue")
	{
		textBox1.ForeColor = Color.Blue;
	}
}
Then just add an event for TextChanged or w/e on that text box event panel
And then inside that just do
GetColor();

should work