Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I am using visual studio 2010 to build a windows forms app. I want to be able to drag the form to another location or minimize the form while the app is running. Is that possible? Here's an example. I have a form with one button. Here's the code associated with the button:
VB
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim time0 As Integer
    Dim time1 As Integer
    For time0 = 0 To 1000000000
        time1 = time0
    Next
End Sub


Before I push the button, I can drag the form or minimize it. Once I push the button, the form is frozen until the code stops running.
Posted
Comments
Maciej Los 6-Apr-12 14:07pm    
Tell me what is for "for ... next" loop?
Fred Andres 6-Apr-12 14:09pm    
It's just some code to take some time. My real app is much more complicated.

Add the following inside your loop:
C#
Application.DoEvents();

This tells your code to respond to external events, such as moves or resizes.
 
Share this answer
 
v2
Comments
Fred Andres 6-Apr-12 14:07pm    
Thanks.
Another option is to use the Background Worker Class[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900