我有4个文本框和1个按钮。 当按下按钮时,它会ping 4个IP地址,然后根据ping状态更改文本框颜色。运行时更改TextBox BackColor
我想要做的是,当按下按钮时,所有文本框的背景颜色在ping开始之前变为白色。
我写了下面的代码,但没有奏效。
我的代码:
public void Clear1()
{
txtHKB1.BackColor = Color.Yellow;
txtHKB2.BackColor = Color.Yellow;
txtHKB3.BackColor = Color.Yellow;
txtHKB4.BackColor = Color.Yellow;
}
public void Clear2()
{
txtHKB1.Text = "";
txtHKB2.Text = "";
txtHKB3.Text = "";
txtHKB4.Text = "";
}
private void btnConnect_Click(object sender, EventArgs e)
{
//b.Baglan("192.168.20.50","9050");
}
private void btnSistemIzle_Click(object sender, EventArgs e)
{
Thread th1 = new Thread(new ThreadStart(Clear1));
Thread th2 = new Thread(new ThreadStart(Clear2));
th1.Start();
th2.Start();
SistemIzle("192.168.20.60");
SistemIzle("192.168.20.80");
SistemIzle("192.168.20.100");
SistemIzle("192.168.20.120");
counter2++;
}
public void SystemAnalyse(string ip)
{
try
{
IPAddress ipAddress = Dns.GetHostEntry(ip).AddressList[0];
//for (int i = 0; i < 3; i++)
//{
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingReply pingReply = ping.Send(ipAddress);
counter++;
//MessageBox.Show(pingReply.Buffer.Count().ToString() + pingReply.RoundtripTime.ToString()
// + pingReply.Options.Ttl.ToString() + pingReply.Status.ToString());
//System.Threading.Thread.Sleep(100);
//}
}
catch
{
//MessageBox.Show("Başarısız Girişim!");
fail++;
}
if (counter % 4 == 1 && fail == 0)
{
txtHKB1.BackColor = Color.Green;
txtHKB1.Text = " Yayinda";
}
if (counter % 4 == 1 && fail == 1)
{
fail = 0;
txtHKB1.BackColor = Color.Red;
txtHKB1.Text = " Kapalı";
}
if (counter % 4 == 2 && fail == 0)
{
txtHKB2.BackColor = Color.Green;
txtHKB2.Text = " Yayinda";
}
if (counter % 4 == 2 && fail == 1)
{
fail = 0;
txtHKB2.BackColor = Color.Red;
txtHKB2.Text = " Kapalı";
}
if (counter % 4 == 3 && fail == 0)
{
txtHKB3.BackColor = Color.Green;
txtHKB3.Text = " Yayinda";
}
if (counter % 4 == 3 && fail == 1)
{
fail = 0;
txtHKB3.BackColor = Color.Red;
txtHKB3.Text = " Kapalı";
}
if (counter % 4 == 0 && fail == 0)
{
txtHKB4.BackColor = Color.Green;
txtHKB4.Text = " Yayinda";
}
if (counter % 4 == 0 && fail == 1)
{
fail = 0;
txtHKB4.BackColor = Color.Red;
txtHKB4.Text = " Kapalı";
}
}
我做错了什么? 我最好的问候...
的文本框,如果它们是什么颜色不是白色的? – LarsTech 2012-02-03 14:04:04