更改光标 VB.NET
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9134360/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change cursor VB.NET
提问by Naster
I can't change the cursor when it's a ToolStripButton.click event.
当它是 ToolStripButton.click 事件时,我无法更改光标。
I got 2 buttons that call "Rechercher".
我有 2 个按钮,称为“Rechercher”。
EDITED : Only the Button is working. It seems that the ToolStripButton cancel my cursor... Thx for the help
编辑:只有按钮在工作。似乎 ToolStripButton 取消了我的光标......感谢帮助
Public Class FenetrePrincipale
Private WithEvents _btnRechercher As New Windows.Forms.ToolStripButton("Rechercher")
Private WithEvents btnRechercherAccesBtn As New Button
Private Sub Rechercher(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _btnRechercher.Click, btnRechercherAccesBtn.Click
Try
Me.Cursor = Cursors.WaitCursor
'WAITING FOR THE CODE TO FINISH (2 sec)
Finally
Me.Cursor = Cursors.Default
End Try
End Sub
End Class
采纳答案by Naster
This is the only way I got this to work.
这是我让它工作的唯一方法。
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
Public Class FenetrePrincipale
Private WithEvents _btnRechercher As New Windows.Forms.ToolStripButton("Rechercher")
Private WithEvents btnRechercherAccesBtn As New Button
Private Sub Rechercher(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRechercherAccesBtn.Click
Try
Me.Cursor = Cursors.WaitCursor
'code...
Finally
Me.Cursor = Cursors.Default
End Try
End Sub
Private Sub RechercherToolStripButton(ByVal sender As Object, ByVal e As System.EventArgs) Handles _btnRechercher.Click
Me.UseWaitCursor = True
SendMessage(Me.Handle, &H20, Me.Handle, New IntPtr(1))
Rechercher(Nothing, Nothing)
Me.UseWaitCursor = False
End Sub
End Class
回答by FeRtoll
Maybe you should try something sampler like:
也许您应该尝试一些采样器,例如:
Private Sub MainFrame_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Search()
End Sub
Private Sub Search()
Try
Me.Cursor = Cursors.WaitCursor
UseWaitCursor = True
Application.DoEvents()
Threading.Thread.Sleep(1000) 'WAITING FOR THE CODE TO FINISH
Finally
UseWaitCursor = False
Me.Cursor = Cursors.Default
Application.DoEvents()
End Try
End Sub
The problem is you don't have any pause where code should execute so it is doing to fast.
问题是你在代码应该执行的地方没有任何停顿,所以它做得很快。