我有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