• c# Form 스타일 None 에서 폼 늘리기

    c# Form 스타일 None 에서 폼 늘리기

    c# Form 스타일 None 일때에도 폼을 늘릴수 있습니다.

     

            private const int
             HTLEFT = 10,
             HTRIGHT = 11,
             HTTOP = 12,
             HTTOPLEFT = 13,
             HTTOPRIGHT = 14,
             HTBOTTOM = 15,
             HTBOTTOMLEFT = 16,
             HTBOTTOMRIGHT = 17;
    
            const int _ = 10; // you can rename this variable if you like
    
            Rectangle Top { get { return new Rectangle(0, 0, this.ClientSize.Width, _); } }
            Rectangle Left { get { return new Rectangle(0, 0, _, this.ClientSize.Height); } }
            Rectangle Bottom { get { return new Rectangle(0, this.ClientSize.Height - _, this.ClientSize.Width, _); } }
            Rectangle Right { get { return new Rectangle(this.ClientSize.Width - _, 0, _, this.ClientSize.Height); } }
    
            Rectangle TopLeft { get { return new Rectangle(0, 0, _, _); } }
            Rectangle TopRight { get { return new Rectangle(this.ClientSize.Width - _, 0, _, _); } }
            Rectangle BottomLeft { get { return new Rectangle(0, this.ClientSize.Height - _, _, _); } }
            Rectangle BottomRight { get { return new Rectangle(this.ClientSize.Width - _, this.ClientSize.Height - _, _, _); } }
    
    
            protected override void WndProc(ref Message message)
            {
                base.WndProc(ref message);
    
                if (message.Msg == 0x84) // WM_NCHITTEST
                {
                    var cursor = this.PointToClient(Cursor.Position);
    
                    if (TopLeft.Contains(cursor)) message.Result = (IntPtr)HTTOPLEFT;
                    else if (TopRight.Contains(cursor)) message.Result = (IntPtr)HTTOPRIGHT;
                    else if (BottomLeft.Contains(cursor)) message.Result = (IntPtr)HTBOTTOMLEFT;
                    else if (BottomRight.Contains(cursor)) message.Result = (IntPtr)HTBOTTOMRIGHT;
    
                    else if (Top.Contains(cursor)) message.Result = (IntPtr)HTTOP;
                    else if (Left.Contains(cursor)) message.Result = (IntPtr)HTLEFT;
                    else if (Right.Contains(cursor)) message.Result = (IntPtr)HTRIGHT;
                    else if (Bottom.Contains(cursor)) message.Result = (IntPtr)HTBOTTOM;
                }
            }

     

    운영하는 c# 소스코드에 그대로 복사해서 넣기만 하면 자동으로 처리됩니다.

    저는 위의 코드보다 아래코드가 바로 되어서 아래 코드를 이용하고 있습니다.

    this.FormBorderStyle, DoubleBuffered, SetStyle 부분은 삭제를 하더라도 잘 돌아가더군요.

     

    참조: https://stackoverflow.com/questions/2575216/how-to-move-and-resize-a-form-without-a-border