Resize borderless window on bottom right corner

Here’s the code corresponding to Franci’s explanations, I was writing it but he answered meanwhile so vote up his explanation which is good if this code suits your needs.

protected override void WndProc(ref Message m) {
    const int wmNcHitTest = 0x84;
    const int htBottomLeft = 16;
    const int htBottomRight = 17;
    if (m.Msg == wmNcHitTest) {
        int x = (int) (m.LParam.ToInt64() & 0xFFFF);
        int y = (int) ((m.LParam.ToInt64() & 0xFFFF0000) >> 16);
        Point pt = PointToClient(new Point(x, y));
        Size clientSize = ClientSize;
        if (pt.X >= clientSize.Width - 16 && pt.Y >= clientSize.Height - 16 && clientSize.Height >= 16) {
            m.Result = (IntPtr) (IsMirrored ? htBottomLeft : htBottomRight);
            return;
        }
    }
    base.WndProc(ref m);
}

Edit: to write the gripper, you can initialize a new VisualStyleRenderer(VisualStyleElement.Status.Gripper.Normal) and use its PaintBackground() method.

Leave a Comment