Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working with a application, I want disable move form. but I don't know how do it?
Posted

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.ShowInTaskbar = false;
       this.ControlBox = false;
       this.Text = null;
    } //NonMovableForm
  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.


The idea is to exclude all default means of dragging a form: the title bar and the non-client icon menu which contains move command.

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

—SA
 
Share this answer
 
v2
Comments
Asish Limbu 2-Aug-11 2:11am    
Good Stuff.+5.
Sergey Alexandrovich Kryukov 2-Aug-11 2:13am    
Thank you, Asish.
--SA
Here are a few ways you can approach this design issue:

1. realize that you are using a WinForm in ways that are not-standard, and consider using another type of container:

a. even if you implement the LocationChanged event in the WinForm to automatically reset the Location of the Form back to some fixed place: you will still get a visual artifact as you attempt to move the Form ... depending on OS visual settings ... such as: a moving outline of the Form's bounding rectangle.

2. if you really have to make a Form movable at some times, and fixed at other times, and you are willing to put up with the appearance and disappearance of the Form's title bar, all you have to do to completely hide the title bar and border is set ControlBox to 'false.

3. if you must have a Form that retains the same appearance at all times ... i.e., always has a title bar ... and which you can control the movability of with no visual artifacts, you are going to have use the Win API to create a WndProc, and handle the SC_Move message.

4. finally, you can use a Form with no Text caption, and FormBorderStyle set to 'FixedToolWindow, and ControlBox set to 'false, and put your own ui-equivalent to the Title Bar on the Form, and then implement your own click-drag-move functionality, which you can turn off or on when you wish.
 
Share this answer
 
Comments
Asish Limbu 2-Aug-11 2:11am    
Perfect.+5.
Sergey Alexandrovich Kryukov 2-Aug-11 2:14am    
My 5 for a number of really good points.
--SA

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