-
June 3rd, 2005, 06:26 AM
#1
Form losing focus stops counter
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer = 1
For i = 1 To 100000
Me.Label1.Text = Str(i) & " of 100000"
Me.Refresh()
Next
End Sub
When I click my Button1 and then click on another window, say Windows Explorer or Outlook, etc., my VB.NET form obviously loses focus. When I come back to it it doesn't refresh until the loop is completed.
Is there anyway to either keep the VB.NET form modal; not just within my VB.NET app but throughout all of the windows that are up on my PC?
Or is there a way to keep it running in the background or refresh it upon activating? I've tried the activated event, but it still waits for the for loop to finish.
Any thoughts? Thanks
Ben
-
June 3rd, 2005, 06:52 AM
#2
Re: Form losing focus stops counter
To make your form respond to other events while doing heavy jobs, you can use Application.DoEvents() Method.
So your early code can be fixed to the below given form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer = 1
For i = 1 To 100000
Application.DoEvents()
Me.Label1.Text = Str(i) & " of 100000"
Me.Refresh()
Next
End Sub
Hope that solves your prob
-
June 3rd, 2005, 08:23 AM
#3
Re: Form losing focus stops counter
Another way is to put your loop on it's own thread.
-
June 3rd, 2005, 10:24 AM
#4
Re: Form losing focus stops counter
Cool, it works; thanks much
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|