Originally posted by Trefad
How would I go about making an if statement with a number. Example... if(textBox1 = 1)... Only that part. I always get errors when I try. It says that it cannot convert int to a windows form. Hope some one knows
You have multiple problems in that code, one is textBox1 itself IS a windows form, what you want is the .text property. Another is you need a double equals (==), not a single equals (=). One equal sign signifies assignment, for a comparison you want to use a double. Now since you want to compare directly with an integer you'd want to cast textBox1's text as an integer as well, to do this you would use the following code:
int myValue = int.Parse(textBox1.Text); /* rename myValue to a suitable variable name */
if(myValue == 1)
{
/* code here */
}
Edit: If you wanted to get secure with it to prevent unpredictable / desirable results then you can write up a little check function to ensure textBox1 only contains an integer value, as if a string is passed in and your program tries to convert it, as I said you might get unpredictable results.