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
LVL 1
Xavior2K3Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

andrewharrisCommented:
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
0
nishikanthCommented:
cehck this
http://dotnet.mvps.org/dotnet/faqs/?id=nonmoveableform&lang=en

another method will be ...

Protected Overrides Sub WndProc(ByRef m As Message)
 const Integer WM_NCLBUTTONDOWN = 161
 const Integer WM_SYSCOMMAND = 274
 const Integer HTCAPTION = 2
 const Integer SC_MOVE = 61456
 
If (m.Msg = WM_SYSCOMMAND) &&(m.WParam.ToInt32() = SC_MOVE) Then
 Return
End If
 
If (m.Msg = WM_NCLBUTTONDOWN) &&(m.WParam.ToInt32() = HTCAPTION) Then
Return
End If

MyBase.WndProc( m)
End Sub
 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andrewharrisCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.