質問する質問する
 

回答済みCode Required

  • 2009年6月18日 12:12SHUJA ABBAS ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     

    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

回答

  • 2009年6月22日 11:05Rong-Chun ZhangMSFT, モデレータユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     回答済み

    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!

すべての返信

  • 2009年6月22日 11:05Rong-Chun ZhangMSFT, モデレータユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     回答済み

    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!
  • 2009年6月25日 3:08Catherine Sea ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     

    Thanks for the code, Rong-Chun.

    Catherine Sea
    http://www.scmsoftwareconfigurationmanagement.com