时间编程问题请教
向来对时间编程不是很了解。现在遇到一个问题一个label控件 内容为整数 现在要按照一定的间隔秒时自动+1
这个间隔秒数在一个文本框textbox中由用户自己设定。比如用户输入10 那么这个label控件的值每10秒自动+1
该何如做呢
谢谢大家
--------------------编程问答-------------------- 哦。可能还要加一个按钮 可以实现开始。和暂停 --------------------编程问答-------------------- webform 要用javascript的 setInterval
winform 用Timer --------------------编程问答-------------------- 我知道是timer控件 就是不知道怎么用。。。。
谁能给地段代码?谢谢 --------------------编程问答--------------------
--------------------编程问答-------------------- 窗口里拖一个按钮 一个文本框 一个标签 一个时间控件 --------------------编程问答-------------------- 这个是毫秒的,改成秒的
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Text = "暂停"
Label1.Text = "0"
TextBox1.Text = "1000"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "暂停" Then
Button1.Text = "开始"
Timer1.Enabled = True
Else
Button1.Text = "暂停"
Timer1.Enabled = False
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Timer1.Interval = CInt(TextBox1.Text)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = CStr(CLng(Label1.Text) + 1)
End Sub
End Class
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Text = "暂停"
Label1.Text = "0"
TextBox1.Text = "1"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "暂停" Then
Button1.Text = "开始"
Timer1.Enabled = True
Else
Button1.Text = "暂停"
Timer1.Enabled = False
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Timer1.Interval = CInt(TextBox1.Text)×1000
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = CStr(CLng(Label1.Text) + 1)
End Sub
End Class
--------------------编程问答-------------------- 赞ls~ --------------------编程问答--------------------
正解
补充:.NET技术 , VB.NET