专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

简单有关问题:Timer控件如何用啊 100分求解

发布时间:2011-06-23 16:00:23 文章来源:www.iduyao.cn 采编人员:星星草
简单问题:Timer控件怎么用啊? 100分求解
有一个Button   A   是向串口发送信息的.
添加一个Timer1为起到能向串口循环发送信息.
比如:人为设定延时5000ms   ,   次数:5次   ,   就是说每隔5000ms就执行一次Button_Click事件,一共执行5次.

怎么实现上述操作呢?

谢谢!

------解决方案--------------------
做一个Send()函数,把要发送的内容写到里面,Button 和Timer都调用这个Send,
定义一个全局计数变量,在Timer中每调用一次+1,如果他> 5,Timer设置为false
------解决方案--------------------
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
btn_Click(sender, e)
.
.
------解决方案--------------------
看不明白??我写的很清楚了吧?!

int num;
...
num=0;
...
Buttn事件:Send()
Timer事件:if(num> 5) Timer设置为false;Send(),num++;
Send(){你发送的具体代码}
------解决方案--------------------
Button_Click事件只用把Timer1的Enabled属性设为true即可。在Timer1的循环事件中加入代码
count=count-1 'count为设置的循环次数
if count=0 then
timer1.Enabled=false
else
'加入串口发送数据

------解决方案--------------------
Public Class Form1
Dim count As Int32

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Timer1.Enabled = False
End Sub

Private Sub ButtonA_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonA.Click
count = 0
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
send()
If (count = 4) Then
Timer1.Enabled = False
End If
End Sub

Private Sub send()
'send seriel port signal code
count += 1
End Sub

End Class
------解决方案--------------------
同意楼上
------解决方案--------------------
Public num As Integer = 0
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
if num > 5
Timer1.Enabled = False
End if
btn_Click(sender, e)
num += 1
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: