?
Solved

Not allowing user to move a form

Posted on 2004-11-02
3
Medium Priority
?
159 Views
Last Modified: 2010-04-24
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
0
Comment
Question by:Xavior2K3
  • 2
3 Comments
 
LVL 4

Expert Comment

by:andrewharris
ID: 12479284
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
 
LVL 8

Accepted Solution

by:
nishikanth earned 2000 total points
ID: 12479465
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
 
LVL 4

Expert Comment

by:andrewharris
ID: 12479728
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

862 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