Nickeay

hi,

I just want to make a Form not movable in C# VS2005. I want it always stays in the center of the screen. Users can not drag it around. How to do that

I tried set the location to the value that I want in Form_Move() handler, but I can still see the shade when I drag it.

Thanks.



Re: Windows Forms General How to make a window Form stay in the same location all the time?

myoungbl

I'm not sure you will find this feasable, but if you remove the control box and the form text property, there will NOT be a place to grab the form to move it.

I don't see any other solution besides the one you've already tried.






Re: Windows Forms General How to make a window Form stay in the same location all the time?

Nickeay

hammm, figured out. Here is how:

public static readonly int HTNOWHERE = 0;

//public static readonly int HTCLIENT = 1;

public static readonly int HTCAPTION = 2;

public static readonly int WM_NCHITTEST = 0x0084;

protected override void DefWndProc(ref Message m)

{

base.DefWndProc(ref m);

if (m.Msg == WM_NCHITTEST)

{

if (HTCAPTION == m.Result.ToInt32())

m.Result = new IntPtr(HTNOWHERE);

}

}





Re: Windows Forms General How to make a window Form stay in the same location all the time?

nobugz

You'd need to disable the system menu too to disable moving the form with the keyboard. Check this thread for an alternative. Just out of interest: what kind of app are you creating where you'd want to disallow this





Re: Windows Forms General How to make a window Form stay in the same location all the time?

Nickeay

You are right, thanks for you input.

The reason our users want to do this is because, we have some windows like A shows B, B shows C. They only want user to see the top window, which is C. The don't evnet want to see A and B. So, we make all of them in the same size, and don't allow them to move. It is kinda dumm, but, clients often give us headache like this.Smile