2016-03-24 16 views
-1

私はビジュアルベーシックで初めてで、ユーザーが設定した時間間隔で一連のコードを実行しようとしています後者はいつでもテキストボックスから変更できます。私が作成したインターフェースを添付してください。ユーザーがテキストボックスからタイマーの時間間隔を設定するビジュアルベーシックでタイマーを制御する方法

​​

+0

'私がしようとしています...実際に何かをしようとするコードはどこにありますか?コードなしであなたを導くことは難しい – Plutonix

+0

あなたがすでに試したことを私たちに教えてください。 entioreソリューションは作成しませんが、バグ修正にお役立てします。 – SubliemeSiem

答えて

0

私は間隔値にユーザーがTextBox.TextChangedイベントを処理することにより、のTextBox内を右整数値を置きます(あなたが適切なエラー - を追加するか、できないことを毎回設定することができ提案します取り扱い)。

例:あなたは、現在の間隔をお知りになりたい場合は

Friend WithEvents Timer1 As New System.Windows.Forms.Timer 

Private Sub ResetTimerInterval(ByVal tmr As Timer, ByVal interval As Integer) 
    If (tmr IsNot Nothing) Then 
     With tmr 
      .Stop() 
      .Enabled = False 
      .Interval = interval 
      .Enabled = True 
      .Start() 
     End With 
    End If 
End Sub 

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) _ 
Handles TextBox1.TextChanged 

    Dim value As Integer 

    If Integer.TryParse(DirectCast(sender, TextBox).Text, value) Then 
     Me.ResetTimerInterval(value) 
    End If 

End Sub 

は、あなたがプロパティを追加することによって、それを追跡することができます

Friend WithEvents Timer1 As New System.Windows.Forms.Timer 

Private Property TimerInverval As Integer 
    Get 
     Return Me.timerIntervalB 
    End Get 
    Set(ByVal value As Integer) 
     If (value <> Me.timerIntervalB) Then 
      Me.timerIntervalB = value 
      Me.ResetTimerInterval(value) 
     End If 
    End Set 
End Property 
' Backing field. 
Private timerIntervalB As Integer 

Private Sub ResetTimerInterval(ByVal tmr As Timer, ByVal interval As Integer) 
    If (tmr IsNot Nothing) Then 
     With tmr 
      .Stop() 
      .Enabled = False 
      .Interval = interval 
      .Enabled = True 
      .Start() 
     End With 
    End If 
End Sub 

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) _ 
Handles TextBox1.TextChanged 

    Dim value As Integer 

    If Integer.TryParse(DirectCast(sender, TextBox).Text, value) Then 
     Me.timerIntervalB = value 
    End If 

End Sub 
+0

貴重なご協力をいただき、ありがとうございます。試してみる。 – luvin

+0

@luvin私は助けてうれしいです。ありがとう、歓迎しています。 – ElektroStudios

関連する問題