2013-10-20 134 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