Link to home
Start Free TrialLog in
Avatar of Xavior2K3
Xavior2K3

asked on

Not allowing user to move a form

Hi,

I have some MDI app and i dont want the users to be able to move the windows.  How i can stop the user being able to move the form by clicking on the title bar?

Thanks,
Mike
Avatar of andrewharris
andrewharris

Place this in the form code:

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Const WM_NCHITTEST As Integer = &H84
        Const HTCLIENT As Integer = &H1
        Const HTCAPTION As Integer = &H2

        Select Case m.Msg
            Case WM_NCHITTEST
                MyBase.WndProc(m)
                If (m.Result.ToInt32 = HTCAPTION) Then
                    m.Result = IntPtr.op_Explicit(HTCLIENT)
                End If
                Exit Sub
        End Select

        MyBase.WndProc(m)
    End Sub

Andrew
ASKER CERTIFIED SOLUTION
Avatar of nishikanth
nishikanth

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I like that one better, just ignores the request as apposed to the example I gave which tricks it into thinking you are clicking the form area.

Andrew