我有一点问题.我将光标设置为等待状态.调用PrintDialog后,光标返回默认状态.我无法再次将光标设置为等待状态.代码是这样的:
Cursor.Current = Cursors.WaitCursor
[...]
Dim result As DialogResult = printDialog.ShowDialog()
If result = DialogResult.Cancel Then
Return
End If
Cursor.Current = Cursors.WaitCursor
[...]
最佳答案 我刚用你的代码做了一个小测试.使用你的代码时,我的VS2012没有显示Cursor.Current,但在使用它时没有抛出任何异常.所以我改成了
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
并且在显示printDialog之后WaitCursor停留了.
编辑:找到一个很好的解释Cursor.Current and Cursor之间的差异!
EDIT2:我改变了我的代码,以利用上面提到的@HansPassant的例子中的HourGlass类.即使您输入textBox,WaitCursor也会保留.无论如何 – 当我悬停在例如边界上时,我仍然能够失去waitCursor.一个textBox.
总而言之IMO我认为当仍然可以输入文本aso时强制使用waitCursor并不是很好.也许您可以考虑在某种操作完成之前禁用控件,然后再将光标更改回来.
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 – 我希望在将其转换为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