是否可以在我的Visual Basic .NET窗體中檢查每隔X個間隔執行一次函數?Visual Basic .NET:計劃
1
A
回答
4
查看Timer類。
Public Class Form1
Private T As Timer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
T = New Timer()
AddHandler T.Tick, AddressOf TimerTicker
T.Interval = (1000 * 3) 'Every 3 seonds
T.Start()
End Sub
Private Sub TimerTicker(ByVal sender As Object, ByVal ev As EventArgs)
Trace.WriteLine("here")
End Sub
End Class
0
你是說在某個時間間隔運行一個函數嗎?如果是這樣,那麼定時器控制將工作。快速Google search會給你一些定時器教程。
0
這個怎麼樣:使用定時器,,只是用你想要的任何方法替換MessageBox警報。
以下示例實現了一個簡單的間隔計時器,該計時器每五秒鐘發出一次警報。發生警報時,MessageBox將顯示警報已啓動的次數並提示用戶是否應繼續運行計時器。
您可以找到更多詳細信息here。
Public Class Class1
> Private Shared WithEvents myTimer As New System.Windows.Forms.Timer()
> Private Shared alarmCounter As Integer = 1
> Private Shared exitFlag As Boolean = False
>
> ' This is the method to run when the timer is raised.
> Private Shared Sub TimerEventProcessor(myObject As
> Object, _
> ByVal myEventArgs As EventArgs) _
> Handles myTimer.Tick
> myTimer.Stop()
>
> ' Displays a message box asking whether to continue running the
> timer.
> If MessageBox.Show("Continue running?", "Count is: " &
> alarmCounter, _
> MessageBoxButtons.YesNo) =
> DialogResult.Yes Then
> ' Restarts the timer and increments the counter.
> alarmCounter += 1
> myTimer.Enabled = True
> Else
> ' Stops the timer.
> exitFlag = True
> End If
> End Sub
>
> Public Shared Sub Main()
> ' Adds the event and the event handler for the method that will
> ' process the timer event to the timer.
>
> ' Sets the timer interval to 5 seconds.
> myTimer.Interval = 5000
> myTimer.Start()
>
> ' Runs the timer, and raises the event.
> While exitFlag = False
> ' Processes all the events in the queue.
> Application.DoEvents()
> End While
>
> End Sub
>
> End Class
相關問題
- 1. Visual Basic計算
- 2. CINT與Math.Round在Visual Basic .NET
- 3. Visual basic .net 2008部署
- 4. Visual Basic .Net 3D引擎
- 5. Visual Basic .NET調度線程
- 6. Visual Basic .Net語音命令
- 7. Visual Basic .NET Power Pack 2003
- 8. Visual Basic中的Arraylist .net
- 9. 在Visual Basic .NET中的AddressOf
- 10. 使用select case的Visual Basic會員計劃?
- 11. visual basic和vb.net
- 12. Visual Basic .Net應用程序部署
- 13. Visual Basic .net中圖像的透明度?
- 14. Visual Basic - 調用.net運行時
- 15. Visual Basic(.NET)> randomize listbox picks(unique)
- 16. 從Visual Basic調用.Net類6
- 17. 是否有Visual Basic .NET的機械化?
- 18. Visual Basic .Net - 查詢數據庫
- 19. 在Visual Basic .NET中提取Zip文件
- 20. visual basic .NET連接到sql server compact 3.5
- 21. 從Visual Basic調用.Net類6
- 22. .NET Framework 4.0中的Visual Basic 6.0
- 23. 的Visual Basic .NET反序列化
- 24. float precision visual basic
- 25. Visual Basic編程
- 26. 在任務計劃程序中設置Visual Basic 6.0簡單應用程序
- 27. Visual Basic新手
- 28. visual basic中的彙總統計
- 29. Visual Basic外部類計算器
- 30. Visual Basic Access:參數太少。預計1
謝謝。有用。 – Voldemort 2011-01-06 00:43:31