Form refresh

  • Thread starter Thread starter Tony WONG
  • Start date Start date
T

Tony WONG

i have the following running numbers on the button

the number is running well if i do not move the form

however, if i move the form while number is running.

the number stops running (perhaps running at the back) and then jump to 10
(the end)

how can i make the number running on screen even i move the form? thanks a
lot.


******************************
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim A As Integer = 1
For A = 1 To 10
Button1.Text = A
Me.Refresh()
System.Threading.Thread.Sleep(1000)
Next A
End Sub

End Class
 
Tony WONG said:
i have the following running numbers on the button

the number is running well if i do not move the form

however, if i move the form while number is running.

the number stops running (perhaps running at the back) and then jump
to 10 (the end)

This is the great "ghost window" effect. Read here (2nd paragraph):
http://msdn2.microsoft.com/en-us/library/ms644927(VS.85).aspx
how can i make the number running on screen even i move the form?

In this case, use a System.Windows.Forms.Timer. In other cases, please
ask (and describe the individual case).
thanks a lot.

******************************
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim A As Integer = 1
For A = 1 To 10
Button1.Text = A
Me.Refresh()
System.Threading.Thread.Sleep(1000)
Next A
End Sub

End Class


Armin
 
i have the following running numbers on the button

the number is running well if i do not move the form

however, if i move the form while number is running.

the number stops running (perhaps running at the back) and then jump to 10
(the end)

how can i make the number running on screen even i move the form?  thanks a
lot.

******************************
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        Dim A As Integer = 1
        For A = 1 To 10
            Button1.Text = A
            Me.Refresh()
            System.Threading.Thread.Sleep(1000)
        Next A
    End Sub

End Class

Could you try putting the code which is currently inside your
button1_click event to a Background Worker control's
backgroundWorker1.doWork event and see if it works.

Don't forget to fire bgworker with sth like putting
"BackgroundWorker1.RunAsync" code inside button1_click event.
 
Try something like this:

Public Class Form1
Private WithEvents myTimer As New System.Windows.Forms.Timer
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles
Button1.Click
RemoveHandler Button1.Click, AddressOf Button1_Click
myTimer.Interval = 10
myTimer.Start()
End Sub
Private Sub myTimer_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles myTimer.Tick
myTimer.Interval = 1000
Static Cnt As Integer
Cnt += 1
Button1.Text = Cnt
If Cnt >= 10 Then
Cnt = 0
myTimer.Stop()
AddHandler Button1.Click, AddressOf Button1_Click
End If
End Sub
End Class
 
Back
Top