1

How can I make a borderless form to sizable by grabbing in 5px outside the form?

I have try the way with WndProc overriding, but that not working over child controls and could not be used outside the form.

There is any else solution to resize borderless form like any other window?

  • 2
    "like any other window" -- There's no borderless windows with OS-level resizing support. – Blindy Nov 22 '18 at 19:45
  • Possible duplicate of [How to move and resize a form without a border?](https://stackoverflow.com/questions/2575216/how-to-move-and-resize-a-form-without-a-border) – 41686d6564 stands w. Palestine Nov 22 '18 at 20:50
  • Look at my comment to aleroot's answer. – user5175857 Nov 22 '18 at 20:56
  • @Blindy For example, office softwares is custom designed form and its sizable from few pixels outside the painted form. How is possible to make custom designed form like that? – user5175857 Nov 22 '18 at 21:00
  • It cannot be "outside" the form, whatever window is below it gets the mouse event. [Look here](https://stackoverflow.com/a/2575452/17034), possibly [here](https://stackoverflow.com/a/7692496/17034) if the real problem is that you have a control flush against the edge. – Hans Passant Nov 22 '18 at 21:19
  • @HansPassant Is it maybe possible to simulate this event message with windows hook for mouse location? – user5175857 Nov 22 '18 at 21:34
  • @user5175857, what you're seeing is trickery, I'm talking about what your OS gives you. *There is no OS-level resizing support for borderless windows.* – Blindy Nov 23 '18 at 17:33

1 Answers1

0
protected override void WndProc(ref Message m){
        const int RESIZE_HANDLE_SIZE = 10;

        switch (m.Msg)
        {
            case 0x0084/*NCHITTEST*/ :
                base.WndProc(ref m);

                if ((int)m.Result == 0x01/*HTCLIENT*/)
                {
                    Point screenPoint = new Point(m.LParam.ToInt32());
                    Point clientPoint = this.PointToClient(screenPoint);
                    if (clientPoint.Y <= RESIZE_HANDLE_SIZE)
                    {
                        if (clientPoint.X <= RESIZE_HANDLE_SIZE)
                            m.Result = (IntPtr)13/*HTTOPLEFT*/ ;
                        else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
                            m.Result = (IntPtr)12/*HTTOP*/ ;
                        else
                            m.Result = (IntPtr)14/*HTTOPRIGHT*/ ;
                    }
                    else if (clientPoint.Y <= (Size.Height - RESIZE_HANDLE_SIZE))
                    {
                        if (clientPoint.X <= RESIZE_HANDLE_SIZE)
                            m.Result = (IntPtr)10/*HTLEFT*/ ;
                        else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
                            m.Result = (IntPtr)2/*HTCAPTION*/ ;
                        else
                            m.Result = (IntPtr)11/*HTRIGHT*/ ;
                    }
                    else
                    {
                        if (clientPoint.X <= RESIZE_HANDLE_SIZE)
                            m.Result = (IntPtr)16/*HTBOTTOMLEFT*/ ;
                        else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
                            m.Result = (IntPtr)15/*HTBOTTOM*/ ;
                        else
                            m.Result = (IntPtr)17/*HTBOTTOMRIGHT*/ ;
                    }
                }
                return;
        }
        base.WndProc(ref m);
    }

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.Style |= 0x20000; // <--- use 0x20000
            return cp;
        }
    }
vizona
  • 1
  • 1