2013-10-20 133 views
-2

我有這個問題,我想設置這樣一個計時器,當我在我的程序點擊按鈕:更改文本標籤和顏色通過點擊按鈕

第一個文本標籤"Not Connected"紅色)更改"Verifying"顏色爲綠色),並經過一段時間它permenatly變爲"Connected"顏色爲綠色

我怎麼做在於:

回答

0

既然你不代碼與計時器提供瞭解什麼是你想幹什麼我不能給出一個更好的答案,你可以適應這個代碼,我做的事:

Public Class Form1 

Private Enum State 
    NotConnected = 141 ' Red 
    Verifying = 53 ' DarkGreen 
    Connected = 79 ' Green 
End Enum 

Private Sub Button1_Click(sender As Object, e As EventArgs) _ 
Handles Button1.Click 

    Select Case Label1.Tag 

     Case Nothing 
      SetLabelState(Label1, "Not Connected ", State.NotConnected) 

     Case State.NotConnected 
      SetLabelState(Label1, "Verifying", State.Verifying) 

     Case State.Verifying 
      SetLabelState(Label1, "Connected", State.Connected) 

     Case State.Connected 
      ' Do nothing here 

     Case Else 
      Throw New Exception("Select case is out of index") 

    End Select 

End Sub 

Private Sub SetLabelState(ByVal lbl As Label, _ 
          ByVal txt As String, _ 
          ByVal col As State) 

    lbl.BackColor = Color.FromKnownColor(CType(col, KnownColor)) 
    lbl.Tag = col 
    lbl.Text = txt 

End Sub 

End Class