- Method #1 changes the state of the cursor for the selected form only, moving the cursor off the form will have it change into the state set by the form you are then over.
- Method #2 changes the state of the cursor for all of your application
' --- Method #1, change the cursor for the owner object (eg a form) This is the same as
' Setting the cursor property at design time (see image)
' change cursor to hourglass
Me.Cursor() = Cursors.WaitCursor()
' change back to normal
Me.Cursor() = Cursors.Default()
' --- This may generaly be better
' change cursor to hourglass
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
' change back to normal
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
|
|
Many times usage of Application.Doevents will also mess with the cursor state, so if you want to make sure you can maintain a waitcursor continiously in some operation, move any application.doevenst's outside the worker loop like:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' --- Have other stuff updated
Application.DoEvents()
' --- Set wait cursor (HourGlass)
Cursor.Current = Cursors.WaitCursor
' --- Do important stuff here
' --- Set the cursor back to normal
Cursor.Current = Cursors.Default
End Sub