【发布时间】:2020-02-08 18:41:09
【问题描述】:
我正在尝试在 Windows 窗体的文本框中设计一个语句,以便在给定变量的输入为 <、> 或 == 时背景颜色会发生变化。
我一直在尝试使用 if/else if 和 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;
}
}
}
使用此代码,我已经能够获得红色背景颜色,但无论我在文本框中引入的值如何,它都不会改变。
【问题讨论】:
-
考虑在更改颜色后刷新/重绘窗口。您可以尝试在表单上调用 this.Invalidate() 或 this.Refresh()。
标签: c# arcgis arcobjects