Fixed window position

  • Thread starter Thread starter Rommel Ladera via .NET 247
  • Start date Start date
R

Rommel Ladera via .NET 247

Does anybody know what's the best way to lock the window's position in .NET besides using Windows API?

Basically, it will prevent the user from moving the windows form.
 
* Rommel Ladera via .NET 247 said:
Does anybody know what's the best way to lock the window's position in .NET besides using Windows API?

Why not use the Windows API for this purpose?! It's what's done for
all windows running on windows, and currently there is no managed way to
do what you want to do.
 
You might be able to do this if you override WndProc and ignore non-client
mouse downs in the titlebar of your form. You would probably want to do some
additional hit testing to allow clicks on the system menu and the maximize,
minimize and close buttons (if they are visible).

private int captionHeight = SystemInformation.CaptionHeight;
private Size captionButtonSize = SystemInformation.CaptionButtonSize;
protected override void WndProc(ref Message m)
{
if(m.Msg == 0xa1) //(WM_NCLBUTTONDOWN)
{
Point pt = this.PointToClient(Control.MousePosition);
//very simple hittest to allow clicks on buttons in the caption
if( pt.Y < captionHeight && pt.X > captionButtonSize.Width - 4 && pt.X <
this.Width - 3 * captionButtonSize.Width)
{
Console.WriteLine(m);
return;// ignore them
}
}
base.WndProc (ref m);
}


==================================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
Back
Top