Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am trying to make a Form Non-Movable. How can I do this??? I have already made it non-resizable, now I just need to make it non-movable.
Thanks in advance!
Posted
Updated 20-Jun-17 13:04pm

Don't do it...

Move the windows where you want it to appears. If you really want it, then perhaps you could ensure that if the user move the windows it stay visible on one monitor.

It can be frustrating to your user not to be able to move a windows. For example, the user might change his monitor resolution, have multiple monitor (he might then prefer to show that windows on another monitor). The user might use one of its screen for a full screen application and then prefer to have your application on another monitor.

By the way, it you prevent your windows from being moved, it might be moved anyway by the system when changing the resoution (depending on how you do it).

A user can install some third party product or write an utility to move the windows anyway.

You will have to correctly handle thing like changes of the resolutions, monitors, desktop area (for example if the user drag the taskbar on another side that the default).

Another application might have decided to do the same as you and thus overlap your windows without the user being able to do anything about it.

Windows was designed that way with a purpoose. Those that do applications that violate the rules might be hated by some.

Doing that might force you to have unsafe code in your application. If the application could underwise be compiled as a safe application, this would be a very bad thing...
 
Share this answer
 
Comments
NY Andrew 12-Jul-11 22:01pm    
I understand exactly what you are saying, but all it is is a Settings pop up form wich I have centered to the parent form and non movable.
Sergey Alexandrovich Kryukov 13-Jul-11 1:20am    
I does not make any difference. Fixed position is evil, due to each and every item listed above. I told you same thing.
--SA
Sergey Alexandrovich Kryukov 13-Jul-11 1:19am    
Good points, my 5. I actually meant the same when I simply put in my solution:
"4. Get ready to receive multiple complaints from the users."
--SA
Sergey Chepurin 13-Jul-11 1:43am    
I don't agree with both of you. If you just say "do not do it" it will force the person to search for solution (probably in vain, may be wrong one) somewhere else. He has to know if it can be implemented or not (and why not). Of cause i do not mean any malicious code!
By the way, it takes just two clicks to find this code on Google/Bing/etc.
But here you can explain him why this is so bad to be implemented in any case.
Philippe Mori 13-Jul-11 11:02am    
It generally a bad idea to assume that the user of our application only use our application... I already give many reasons why we should not works around the system.

As an analogy, what would you think if a car constructor would not make the seat adjustable by assuming that all driver would like "the constructor best seat position". It does not make much sense. Same for forcing a Windows to be at a specific position.
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.


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

—SA
 
Share this answer
 
v3
Comments
NY Andrew 12-Jul-11 17:59pm    
Hello SA again! :) Hmm.. I just tried that but it did not work..
Philippe Mori 12-Jul-11 22:59pm    
You said that you already manged to make it non resizeable... and the above code do all the remainding step to prevent the form to be moved. If you have find a way to still move the form, tell us how.

Without caption, task-bar button and system menu I cannot see how you could move it anyway.
Sergey Alexandrovich Kryukov 13-Jul-11 1:16am    
Andrew, please tell me what do you see. Do you see that the title bar disappeared? It solves the problem of non-movable because there is no a way to move.
--SA
Philippe Mori 12-Jul-11 22:54pm    
Add also this.FormBorderStyle = FormBorderStyle.FixedDialog; (or any other non-moveable border style). This will prevent the form from being "moved" by resizing it... Otherwise, if all properties indicated in step 1 are set as indicated, it is not possible to move the form.
Sergey Alexandrovich Kryukov 13-Jul-11 1:15am    
Sure, I ignored it only because OP said non-resizeable is already done.
--SA
Here it is. Just convert C# to VB.NET.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Jul-11 17:46pm    
Did you check it? It will certainly prevent moving via SYS_COMMAND, but how about dragging by a mouse? At lease you should remove a system icon box.

I've tested my solution, please see.
--SA
Sergey Chepurin 13-Jul-11 1:24am    
I always test the code proposed.
This is VB.NET variant and the window is "non-movable" (for whatever reason it is needed):

Protected Overrides Sub WndProc(ByRef m As Message)
Const WM_SYSCOMMAND As Integer = &H112
Const SC_MOVE As Integer = &Hf010

Select Case m.Msg
Case WM_SYSCOMMAND
Dim command As Integer = m.WParam.ToInt32() And &Hfff0
If command = SC_MOVE Then
Return
End If
Exit Select
End Select
MyBase.WndProc(m)
End Sub
I am using java caz i have once implemented it in inventory system application;

you have to add Componentlistener to the frame and code specific location you want to set.

example

frame.addComponentListener(new ComponentListener(){
@Override
public void componentMoved(ComponentEvent e) {

frame.setSize(200,300);
frame.setAlwaysOnTop(true);
}

});
frame.setLocation(setSize(200,300));
//frame.set
 
Share this answer
 
Comments
[no name] 3-Aug-13 18:06pm    
The question was asked and answered over 2 years ago.
VB.NET does not have a Componentlistener so even if the question were not ancient, your solution would be irrelevant.

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