Poser une questionPoser une question
 

TraitéeCode Required

  • jeudi 18 juin 2009 12:12SHUJA ABBAS Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     

    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

Réponses

  • lundi 22 juin 2009 11:05Rong-Chun ZhangMSFT, ModérateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     Traitée

    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!

Toutes les réponses

  • lundi 22 juin 2009 11:05Rong-Chun ZhangMSFT, ModérateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     Traitée

    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!
  • jeudi 25 juin 2009 03:08Catherine Sea Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     

    Thanks for the code, Rong-Chun.

    Catherine Sea
    http://www.scmsoftwareconfigurationmanagement.com