VBA Tipp: Mauszeiger mit eigenem Icon

Aus DBWiki
Wechseln zu: Navigation, Suche

Problem

Ich möchte in meinem Formular dem Mauszeiger ein eigenes Icon zuweisen.

Lösung

Declare Function LoadCursorFromFile Lib "user32" Alias _
"LoadCursorFromFileA" (ByVal lpFileName As String) As Long
Declare Function SetCursor Lib "user32" _
(ByVal hCursor As Long) As Long
Public Function PointM(strPathToCursor As String)
Dim lngRet As Long
lngRet = LoadCursorFromFile(strPathToCursor)
lngRet = SetCursor(lngRet)
End Function

Aufruf

Im Detailbereich des Formulars:

Private Sub Detailbereich_MouseDown(Button As Integer, Shift As Integer, _
                                    X As Single, Y As Single)
Call PointM("C:\Test.ico")
End Sub
 
Private Sub Detailbereich_MouseMove(Button As Integer, Shift As Integer, _
                                    X As Single, Y As Single)
Call PointM("C:\Test.ico")
End Sub
 
Private Sub Detailbereich_MouseUp(Button As Integer, Shift As Integer, _
                                  X As Single, Y As Single)
Call PointM("C:\Test.ico")
End Sub


Wiki hinweis.png Anmerkung: Einfach dem Eventhandler im Formular bereitstellen.