Solved

Stopping a Form from being Dragged

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now