Я использовал решения Дона Киркби и Мэтью Феррейры и создал свое собственное решение, объединяющее оба. Я добавил StatusStrip с именем «resizeHandle», сделал его размером 20x20 пикселей и прослушал его события.
public class CustomForm : Form
{
private const int WmNcLButtonDown = 0xA1;
private const int HtBottomRight = 17;
private const int wmNcLButtonUp = 0xA2;
private bool isResizing = false;
[DllImport("user32.dll")]
private static extern int ReleaseCapture();
[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hwnd, int msg, int wparam, int lparam);
private void resizeHandle_MouseDown(object sender, MouseEventArgs e)
{
isResizing = true;
}
private void resizeHandle_MouseMove(object sender, MouseEventArgs e)
{
if (isResizing)
{
// Check if we have released the Left mouse button
isResizing = (e.Button == MouseButtons.Left);
ReleaseCapture();
if (isResizing)
{
SendMessage(Handle, wmNcLButtonDown, HtBottomRight, 0);
}
else
{
// Left Mouse button was released, end resizing.
SendMessage(Handle, wmNcLButtonUp, HtBottomRight, 0);
}
}
}