I just did a little test with your code. When using the code, my VS2012 did not display Cursor.Current , but when using it did not raise any exceptions. 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 WaitCursor stayed after displaying printDialog.
EDIT: Found a pretty good explanation for the difference between Cursor.Current and Cursor !
EDIT2: I modified my code to use the HourGlass class from the @HansPassant example above. WaitCursor now remains, even if you enter a text field. In any case, I could still lose waitCursor when falling over the border, for example. text field.
In general IMO, I think it's not very good to force waitCursor when you can still enter aso text. Perhaps you can turn off the controls until some action is completed, and then cancel the 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 was not mistaken 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
source share