Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       

        Label2.Text = "before"
        Sleep(3000)
        Label1.Text = "after"

    End Sub

When i click the button1, the above code executes. Actually i should display label2 with string "before" and after 3 seconds label1 with string "after". But this is not happening both the labels with name "before" and "after" are displaying after 3 seconds after the form loads and also both the labels are displaying at once.

please solve my problem.

ravikiran032,
Use Thread class method.

hello adapost, but when i click on button,first label text doesn't change to before,But sleep is working, & after some seconds label text is chnage to after

Imports System.Threading
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Label1.Text = "before"
            Thread.Sleep(10000)
            Label1.Text = "after"
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub
End Class

hi ravikiran032,thread.sleep takes time in milliseconds...remember it

Label1.Text = "before"
Label1.Refresh()
Thread.Sleep(10000)
Label1.Text = "after"

hi thx adatapost, hi ravikiran03 u got ur answer

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.