Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have a parent form and I don't allow to move this form. but i can not do this. If in VB6 I can set properties Moveable =False but in VB.NET there is no this properties.

How to do not allow user move form?

Please help me.

thanks in advance
Posted

1 solution

A short preliminary note: there are not parent-child relationships between forms. (I don't mean MDI parent and children, which is not the same thing, also, who needs MDI? :-)) There are owner and owned forms though; I would highly recommend to have all forms owned by the main form which helps application integrity.

Now, about preventing form dragging. Weird enough, this is ridiculously simple to achieve:

  1. Add the following code to the the form constructor:
    C#
    public NonMovableForm() {
       InitializeComponent();
       //add this:
       this.ControlBox = false;
       this.Text = null;
    } //NonMovableForm


    If you want to do the same for a non-main form, I would highly recommend to add ShowInTaskbar = false.
  2. If you really need it, create a fake control imitating a title bar with Close button on it (or not) and dock it to the top of the form.
  3. Do not implement form dragging. :-)
  4. Get ready to receive multiple complaints from the users.
  5. PROFIT? I'm not sure — see the item above.


Anyway, the problem is solved. Decide for yourself if you really want it.

—SA
 
Share this answer
 
v2
Comments
Kim Togo 8-Aug-11 8:07am    
My 5 for the answer.
Sergey Alexandrovich Kryukov 8-Aug-11 8:28am    
Thank you, Kim
ngthtra 8-Aug-11 21:46pm    
my form is ported from VB6 So I can not remove title bar because title bar of form has 3 button(minimum, maximun and exit).
I want only to user can not use mouse to drag ormove my form to other position on screen.

do you have better anyway to resolute my problem?
please help me, thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900