Moving windows forms

  • Thread starter Thread starter Pablo Cedeno
  • Start date Start date
P

Pablo Cedeno

Hi all,

I'm having a problem with a form position.
I need to prevent the user to drag the window. I tried to maximize the
window but i still can move the window.

I found something about override the WndProc method, but there are many
messages returned by the OS, and i don't know which messages should i
override. Maybe i'm working in a wrong way. I also tried with the style
borders and anything seems to work

If somebody can help me, i really appreciate that.
Regards.
 
this would prolly be sort of a hack but if you want the window maximized all
the time
just set the minimumsize of the form to the same size of there resolution on
load..

another idea..

the location event on the form might be something of value as well..
 
Tnx for your help,

I cannot set the minimun size of the application because it will run on
several machines and i cannot ensure that each machine will have the same
resolution screen.

Now i will work in the location event to see if i can get the desire
behavior.

Regards
 
Another issue that i forgot is that the problem is not maximize the form. I
need to prevent the user to drag the window as will. If it's maximized, i
think, it should be "locked" in the screen.

I don't think this is a kind of hack, i really believe this should be the
normal behavior of an application. For example, if you maximize an IE
window, you cannot drag it, the window is locked in the screen, that's what
i need and i don't know why this cannot be done in c# in a simple way(At
least i cannot figure it out)

Regards
 
another way might be: have a timer event check the position every second,
if moved/resized then move/resize it back

John Bickmore
 
Tnx everybody,

I found a solution in another newsgroup, here's the code that i received.
This works great!!

[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.
LayoutKind.Sequential)]
private struct _WINDOWPOS
{
public IntPtr hwnd;
public IntPtr hwndInsertAfter;
public int x;
public int y;
public int cx;
public int cy;
public uint flags;
}

private const int WM_WINDOWPOSCHANGING = 0x0046;
private const int SWP_NOMOVE = 0x0002;

[System.Security.Permissions.PermissionSet(System.Security.Permissions.Secur
ityAction.Demand, Name="FullTrust")]
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_WINDOWPOSCHANGING)
{
_WINDOWPOS p = (_WINDOWPOS)m.GetLParam(typeof(_WINDOWPOS));
p.flags |= SWP_NOMOVE ;
System.Runtime.InteropServices.Marshal.StructureToPtr(p, m.LParam,
false);
m.Result = IntPtr.Zero;
}
else
base.WndProc(ref m);
}

Regards.
 
Back
Top