Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Stopping a Form from being Dragged

Posted on 2006-11-07
3
Medium Priority
?
196 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

636 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