是否可以在我的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. Visual Basic .NET逻辑
- 3. Visual Basic计算
- 4. Visual Basic计算
- 5. Visual Basic Keydown计算
- 6. 在Visual Basic .NET中的AddressOf
- 7. Visual Basic .NET调度线程
- 8. Visual Basic .NET Power Pack 2003
- 9. 的Visual Basic .NET编码
- 10. Visual Basic .Net 3D引擎
- 11. CINT与Math.Round在Visual Basic .NET
- 12. Visual Basic .Net对象和类
- 13. Visual Basic .Net语音命令
- 14. Visual Basic中的Arraylist .net
- 15. Visual basic .net 2008部署
- 16. 使用select case的Visual Basic会员计划?
- 17. 计划在Visual Studio
- 18. visual basic和vb.net
- 19. Visual Basic .NET中:如何从参数
- 20. 从Visual Basic调用.Net类6
- 21. Visual Basic .Net应用程序部署
- 22. 是否有Visual Basic .NET的机械化?
- 23. 在Visual Basic .NET中提取Zip文件
- 24. Visual Basic .net中图像的透明度?
- 25. 从Visual Basic调用.Net类6
- 26. 的Visual Basic .NET反序列化
- 27. Visual Basic - 调用.net运行时
- 28. .NET Framework 4.0中的Visual Basic 6.0
- 29. Visual Basic .Net - 查询数据库
- 30. Visual Basic .net类型'ShellFile'未定义
谢谢。有用。 – Voldemort 2011-01-06 00:43:31