Code Required
I Have this code in my Project and I want to Increase this Number GRADUALLY with DELAY 1 Sec in Label1 so plz tell me what can I do.
Private Sub Command1_Click()
Dim S As Integer
For S = 1 To 100
Label1.Caption = S
NextEnd Sub
Respuestas
Hello ,
You need to call Thread.Sleep method to force the current thread to block for one second. If you working with Windows Form Application, please try something like the following
Delegate Sub SetText(ByVal txt As String)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim t As New Thread(New ThreadStart(AddressOf InvokeMethod))
t.Start()
End SubPrivate Sub IncrementalText(ByVal txt As String)
If Me.Label1.InvokeRequired Then
Dim pro As New SetText(AddressOf IncrementalText)
Me.Invoke(pro, New Object() {txt})
Else
Me.Label1.Text = txt
End If
End SubPrivate Sub InvokeMethod()
For i As Integer = 1 To 100
Thread.Sleep(1000)
IncrementalText(i.ToString())
Next
End Sub
More information,
http://msdn.microsoft.com/en-us/library/ms171728.aspx
Since this forum is for Visual SourceSafe, questions about VB.NET, please ask on VB.NET forum.
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/threads
Thanks,
Rong-Chun Zhang
Please mark the replies as answers if they help and unmark if they don't.
Welcome to the All-In-One Code Framework, a sample code project owned by the MSDN Forum Support team!- Marcado como respuestaRong-Chun ZhangMSFT, Moderadormiércoles, 24 de junio de 2009 9:36
Todas las respuestas
Hello ,
You need to call Thread.Sleep method to force the current thread to block for one second. If you working with Windows Form Application, please try something like the following
Delegate Sub SetText(ByVal txt As String)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim t As New Thread(New ThreadStart(AddressOf InvokeMethod))
t.Start()
End SubPrivate Sub IncrementalText(ByVal txt As String)
If Me.Label1.InvokeRequired Then
Dim pro As New SetText(AddressOf IncrementalText)
Me.Invoke(pro, New Object() {txt})
Else
Me.Label1.Text = txt
End If
End SubPrivate Sub InvokeMethod()
For i As Integer = 1 To 100
Thread.Sleep(1000)
IncrementalText(i.ToString())
Next
End Sub
More information,
http://msdn.microsoft.com/en-us/library/ms171728.aspx
Since this forum is for Visual SourceSafe, questions about VB.NET, please ask on VB.NET forum.
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/threads
Thanks,
Rong-Chun Zhang
Please mark the replies as answers if they help and unmark if they don't.
Welcome to the All-In-One Code Framework, a sample code project owned by the MSDN Forum Support team!- Marcado como respuestaRong-Chun ZhangMSFT, Moderadormiércoles, 24 de junio de 2009 9:36
Thanks for the code, Rong-Chun.
Catherine Sea
http://www.scmsoftwareconfigurationmanagement.com

