Odeslat dotazOdeslat dotaz
 

OdpovědětCode Required

  • 18. června 2009 12:12SHUJA ABBAS Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     

    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
    Next

    End Sub

Odpovědi

  • 22. června 2009 11:05Rong-Chun ZhangMSFT, ModerátorUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     Odpovědět

    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 Sub

        Private 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 Sub

        Private 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!

Všechny reakce

  • 22. června 2009 11:05Rong-Chun ZhangMSFT, ModerátorUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     Odpovědět

    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 Sub

        Private 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 Sub

        Private 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!
  • 25. června 2009 3:08Catherine Sea Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     

    Thanks for the code, Rong-Chun.

    Catherine Sea
    http://www.scmsoftwareconfigurationmanagement.com