Solved

Stopping a Form from being Dragged

Posted on 2006-11-07
3
193 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Formatting DateTime String Value 5 52
C# XML Get Values 4 37
Send parameters via datatable ajax call 4 13
aspx ascx, c# 7 20
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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