更改光标VB.NET



当它是ToolStripButton.click事件时,我无法更改光标。

我有两个按钮叫"Rechercher"。

已编辑:只有按钮在工作。看起来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

也许你应该尝试一些采样器,比如:

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

问题是,在代码应该执行的地方没有任何暂停,所以它正在快速执行。

这是我实现此功能的唯一方法。

<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

相关内容

  • 没有找到相关文章

最新更新