Solved

Stopping a Form from being Dragged

Posted on 2006-11-07
3
194 Views
Last Modified: 2010-04-16
HI,
I have a form that is set for FixToolWindows, but i can still drag it around the screen, i don’t want the user to have this ability but i want to keep this setting….

What do I change to have this happen?
0
Comment
Question by:schenkp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Expert Comment

by:Agarici
ID: 17896239
add this to your form code :
        protected override void WndProc(ref Message m)
        {
            if ( m.Msg == 0x0084/*WM_NCHITTEST*/ )
                return;
            base.WndProc(ref m);
        }
hth,
A.
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 17896254
       const int WM_NCHITTEST = 0x84;
        const int HTCAPTION = 2;
        const int HTCLIENT = 1;

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            if (m.Msg == WM_NCHITTEST  && m.Result.ToInt32() == HTCAPTION)
                m.Result = new IntPtr(HTCLIENT);
        }

This prevents form from moving by mouse, but there is still other way to move form: right-click on title bar, select Move, and then it is possible to move form. Right now I don't know how to prevent this, I will think about this.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17896258
Agarici, your version prevents form from closing by clicking x button. However, if form doesn't have Close button, it is OK.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

717 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