I am trying to design an statement in a textbox of a Windows form so that the backcolor changes if the input given is <
, >
, or ==
to a given variable.
I've been trying with the if
/else if
and switch
.
private void txtPuntosTotalesAGenerar_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
int finalSamplePoints = Convert.ToInt32(Console.ReadLine());
int try1 = 1500;
if (finalSamplePoints > try1)
{
txtPuntosTotalesAGenerar.BackColor = Color.Orange;
}
else if (finalSamplePoints < try1)
{
txtPuntosTotalesAGenerar.BackColor = Color.Red;
}
else if (finalSamplePoints == try1)
{
txtPuntosTotalesAGenerar.BackColor = Color.Green;
}
}
}
With this code I have been able to obtain the red background color, but it is never changing, no matter the values I introduce in the textbox.