I just did a small test with your code. When using your code my VS2012 didn't show up Cursor.Current
but did not throw any exception when using it. So I changed it to
Me.Cursor = Cursors.WaitCursor
Dim result As DialogResult = printDialog.ShowDialog()
If result = DialogResult.Cancel Then
Return
End If
' not necesary any more
'Cursor.Current = Cursors.WaitCursor
and the WaitCursor stayed after showing the printDialog.
EDIT: Found a pretty good explanation on difference between Cursor.Current and Cursor!
EDIT2: I changed my code to make use of HourGlass class from @HansPassant's example stated above. WaitCursor now stays even if you enter a textBox. Anyways - I was still able to get loss of the waitCursor when hovering over the border of eg. a textBox.
All in all IMO I think it's not very good to force a waitCursor when it is still possible to enter text aso. Perhaps you may consider disabling controls until some kind of actions has finished and afterwards change cursor back.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Hourglass.Enabled = True
Dim result As DialogResult = PrintDialog1.ShowDialog()
If result = Windows.Forms.DialogResult.Cancel Then
Return
End If
'Cursor.Current = Cursors.WaitCursor
End Sub
Hourglass.vb - I hope I did not make any mistakes when converting it to vb.net
Public Class Hourglass
Implements IDisposable
Public Shared Property Enabled As Boolean
Get
Return Application.UseWaitCursor
End Get
Set(ByVal value As Boolean)
If value = Application.UseWaitCursor Then Return
Application.UseWaitCursor = value
Dim f As Form = Form.ActiveForm
If Not f Is Nothing AndAlso f.Handle <> IntPtr.Zero Then
SendMessage(f.Handle, 32, f.Handle, 1)
End If
End Set
End Property
<System.Runtime.InteropServices.DllImport("user32.dll")>
Private Shared Function SendMessage(hWnd As IntPtr, msg As IntPtr, wp As IntPtr, lp As IntPtr) As IntPtr
End Function
Public Sub Dispose() Implements IDisposable.Dispose
Enabled = False
End Sub
End Class