Rendere il Cursore invisibile

Per nascondere e far riapparire il cursore (o Mouse per intenderci) bisogna utilizzare la Funzione  ShowCursor delle Api di Windows.


In un modulo Bas inserire:


Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long

'Rende il cursore Invisibile
Public Sub HideMouse()
Dim rtn As Integer
Dim lShowCursor As Long
Do
    lShowCursor = lShowCursor - 1
    rtn = ShowCursor(False)
Loop Until rtn < 0
End Sub

'Rende il cursore Visibile
Public Sub ShowMouse()
Dim rtn As Integer
Dim lShowCursor As Long
Do
    lShowCursor = lShowCursor - 1
    rtn = ShowCursor(True)
Loop Until rtn >= 0
End Sub

Inserire in un Form 3 CommandButton e chiamarli Hide, Show e Cancel, infine inserire il seguente codice:

Option Explicit

Dim flgClick As Boolean

Private Sub Cancel_Click()
ShowMouse
Unload Me
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim AltDown
'controllo pressione tasto Alt
AltDown = (Shift And vbAltMask) > 0
If AltDown Then
    'Se è stato premuto il tasto Alt, controllo se è stato premuto il tasto F1
    If KeyCode = vbKeyF1 Then
        If flgClick Then
            ShowMouse
            flgClick = False
        Else
            HideMouse
            flgClick = True
        End If
    End If
End If
End Sub

Private Sub Form_Load()
'centra il form sullo schermo
Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2 
End Sub

Private Sub Hide_Click()
HideMouse
flgClick = True
End Sub

Private Sub Show_Click()
ShowMouse
flgClick = False
End Sub

Testato su: Windows 98, Windows Me, Windows 2000 Professional