Christian, your solution brought me on the right way but it's lacking copy paste code for the dumb and lazy like me!
Here we go, if you uncomment the commented parts you can move the window around except for the borders.
private void Action_LMouseDownAndMove(object sender, MouseEventArgs e)
{
Point mousePosition = this.PointToClient(System.Windows.Forms.Cursor.Position);
const int WM_NCLBUTTONDOWN = 0xA1;
//const int HT_CAPTION = 0x2;
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
if (mousePosition.X < 20)
{
if (mousePosition.Y < 20)
SendMessage(Handle, WM_NCLBUTTONDOWN, 13, 0);
else if (mousePosition.Y > this.Size.Height - 20)
SendMessage(Handle, WM_NCLBUTTONDOWN, 16, 0);
else
SendMessage(Handle, WM_NCLBUTTONDOWN, 10, 0);
}
else if (mousePosition.X > this.Size.Width - 20)
{
if (mousePosition.Y < 20)
SendMessage(Handle, WM_NCLBUTTONDOWN, 14, 0);
else if (mousePosition.Y > this.Size.Height - 20)
SendMessage(Handle, WM_NCLBUTTONDOWN, 17, 0);
else
SendMessage(Handle, WM_NCLBUTTONDOWN, 11, 0);
}
else if (mousePosition.Y < 20)
SendMessage(Handle, WM_NCLBUTTONDOWN, 12, 0);
else if (mousePosition.Y > this.Size.Height - 20)
SendMessage(Handle, WM_NCLBUTTONDOWN, 15, 0);
//else
// SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
Change the 20 pixel value depending on your taste. I am not 100% sure left/right and top/bottom have exactly the same resize areas or whether one value needs to be 19/21 if you know what I mean... There are some reduction possibilities for the if/else tree here, I know. And instead of 20 I should use a constant.
To change the cursor for showing the user he can resize I use the following code, it's simply a MouseMove Event handler:
this.pictureBox.MouseMove += new MouseEventHandler((a, e) =>
{
Point h = this.PointToClient(System.Windows.Forms.Cursor.Position);
if (h.X < 20)
{
if (h.Y < 20)
{
pictureBox.Cursor = System.Windows.Forms.Cursors.SizeNWSE;
}
else if (h.Y > this.Size.Height - 20)
{
pictureBox.Cursor = System.Windows.Forms.Cursors.SizeNESW;
}
else
{
pictureBox.Cursor = System.Windows.Forms.Cursors.SizeWE;
}
}
else if (h.X > this.Size.Width - 20)
{
if (h.Y < 20)
{
pictureBox.Cursor = System.Windows.Forms.Cursors.SizeNESW;
}
else if (h.Y > this.Size.Height - 20)
{
pictureBox.Cursor = System.Windows.Forms.Cursors.SizeNWSE;
}
else
{
pictureBox.Cursor = System.Windows.Forms.Cursors.SizeWE;
}
}
else if (h.Y < 20)
{
pictureBox.Cursor = System.Windows.Forms.Cursors.SizeNS;
}
else if (h.Y > this.Size.Height - 20)
{
pictureBox.Cursor = System.Windows.Forms.Cursors.SizeNS;
}
else
{
pictureBox.Cursor = System.Windows.Forms.Cursors.Default;
}
});