Not allowing user to move a form

Posted on 2004-11-02
Last Modified: 2010-04-24

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?

Question by:Xavior2K3
    LVL 4

    Expert Comment

    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
                    If (m.Result.ToInt32 = HTCAPTION) Then
                        m.Result = IntPtr.op_Explicit(HTCLIENT)
                    End If
                    Exit Sub
            End Select

        End Sub

    LVL 8

    Accepted Solution

    cehck this

    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
    End If
    If (m.Msg = WM_NCLBUTTONDOWN) &&(m.WParam.ToInt32() = HTCAPTION) Then
    End If

    MyBase.WndProc( m)
    End Sub
    LVL 4

    Expert Comment

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now