Do Loop issue.

newguy

Well-known member
Joined
Jun 30, 2008
Messages
611
Location
Denver Co, USA
Programming Experience
1-3
Hi all, I am working on getting my FlowLayoutPanel to scroll while dragging - cause it does not work with normal measures. I am trying to use a Do Loop which works 'cept that I can get it to stop the loop for a condition. The condition if based on the position of the cursor - so when it is < 120 scroll up, but if they move the cursor > 120 stop scrolling. 120 being near the top of the FLP. Right now it will continue all the way to 0 b/f stopping. I have tried several variations. Any ideas?

VB.NET:
If e.Data.GetDataPresent("myObject") Then
     Dim x As Point = Me.PointToClient(Cursor.Position)
     Do While x.Y < 120
         vsFLP.Value -= 1 ' my custom scrollbar
         Thread.Sleep(50) ' cause it scrolls fast
     Loop
     ....
End If
 
The issue with your code is that you are not getting the new coordinates of your mouse each iteration of the loop. Meaning you find the coordinates of your mouse before the first iteration of the loop and then never update them.

Try this
VB.NET:
Do While x.Y < 120
         x = Me.PointToClient(Cursor.Position)
         vsFLP.Value -= 1 ' my custom scrollbar
         Thread.Sleep(50) ' cause it scrolls fast
     Loop

Maybe someone with more Forms experience can help you but I wouldnt think creating a scroll effect through a do loop and the sleep sub is the best way.
 
Perfect man, I tried making a diff variable, but I just needed to update x.
Thanks very much.
 
Back
Top