Click here to Skip to main content
16,021,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using below code to hide my mouse cursor.Is working fine.But my need is using aws autoscale logic to create new instance ( windows server ).On windows start up i want to launch my application in full-screen mode without mouse cursor.But my mouse cursor is not hidden at very first time ( a new instance launched at very first time ). I already set the form property TopMost = True

What I have tried:

VB
<pre><DllImport("user32")> _
    Private Shared Function ClipCursor(ByVal lpRect As RECT) As Int32
    End Function
    <DllImport("user32")> _
    Private Shared Function ShowCursor(ByVal bShow As Int32) As Int32
    End Function
    <StructLayout(LayoutKind.Sequential)> _
    Private Structure RECT
        Public Left As Int32
        Public Top As Int32
        Public Right As Int32
        Public Bottom As Int32
    End Structure
    Private MouseTrap As RECT

    Public Sub RestoreCursor(ByRef ThisForm As System.Windows.Forms.Form)
        With MouseTrap
            .Top = 0
            .Left = 0
            .Right = Screen.PrimaryScreen.Bounds.Width
            .Bottom = Screen.PrimaryScreen.Bounds.Height
        End With

        ClipCursor(MouseTrap)
    End Sub

    Private Sub MoveCursor()
        ' set the Current cursor, move the cursor's Position,
        ' and set its clipping rectangle to the form. 
        Me.Cursor = New Cursor(Cursor.Current.Handle)
        Cursor.Position = New Point(Me.Left, Me.Top)
        Cursor.Clip = New Rectangle(Me.Left, Me.Top, Me.Width, Me.Height) ', Me.Size)
    End Sub

    Private Sub disableCursor()
        ShowCursor(False)
        MoveCursor()
    End Sub

    Private Sub enableCursor()
        RestoreCursor(Me)
        ShowCursor(True)
    End Sub
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900