Solved

Stopping a Form from being Dragged

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is "public object" in C#? 3 48
MediaHelp 4 23
Printing 1 51
The control parameters are not inputing the value when displaying in a report viewer 13 9
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 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