728x90

FormBorderStyle 을 None 으로 하게되면 전체 창의 크기를 변경할수 없게됩니다.

이를 변경가능하도록 하기위해 찾은 코드입니다.

Win32 API 를 이용한 방법입니다.

대략 순서는 아래와 같습니다.

1. Win32 API를 사용해서 현재 Form Window Window Style을 가져오기

2. WS_CAPTION 스타일 제거

3. WS_BORDER 스타일 추가

4. Win32 API를 사용해서 변경한 Window Style 재설정

아래내용을 전역으로 선언해주고

        [Flags]
        public enum WindowStyle
        {
            WS_OVERLAPPED = 0x00000000,
            WS_POPUP = -2147483648, //0x80000000,
            WS_CHILD = 0x40000000,
            WS_MINIMIZE = 0x20000000,
            WS_VISIBLE = 0x10000000,
            WS_DISABLED = 0x08000000,
            WS_CLIPSIBLINGS = 0x04000000,
            WS_CLIPCHILDREN = 0x02000000,
            WS_MAXIMIZE = 0x01000000,
            WS_CAPTION = 0x00C00000,
            WS_BORDER = 0x00800000,
            WS_DLGFRAME = 0x00400000,
            WS_VSCROLL = 0x00200000,
            WS_HSCROLL = 0x00100000,
            WS_SYSMENU = 0x00080000,
            WS_THICKFRAME = 0x00040000,
            WS_GROUP = 0x00020000,
            WS_TABSTOP = 0x00010000,
            WS_MINIMIZEBOX = 0x00020000,
            WS_MAXIMIZEBOX = 0x00010000,
            WS_TILED = WS_OVERLAPPED,
            WS_ICONIC = WS_MINIMIZE,
            WS_SIZEBOX = WS_THICKFRAME,
            WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW,
            WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
                        WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX),
            WS_POPUPWINDOW = (WS_POPUP | WS_BORDER | WS_SYSMENU),
            WS_CHILDWINDOW = (WS_CHILD)
        }

        private const int GWL_STYLE = -16;

        [DllImport("user32.dll")]
        public static extern Int32 GetWindowLong(IntPtr hWnd, Int32 Offset);

        [DllImport("user32.dll")]
        public static extern Int32 SetWindowLong(IntPtr hWnd, Int32 Offset, Int32 newLong);

Form_Load 이벤트에 아래 내용을 추가합니다.

        private void Form1_Load(object sender, EventArgs e)
        {
            int style = GetWindowLong(this.Handle, GWL_STYLE);

            WindowStyle myStyle = (WindowStyle)style;
            myStyle = myStyle & ~WindowStyle.WS_CAPTION;
            myStyle = myStyle | WindowStyle.WS_BORDER;

            style = SetWindowLong(this.Handle, GWL_STYLE, (int)myStyle);
        }

그런데 불행하게도 완벽하지는 않네요 참고만 해주세요^^;

 

참고

http://blog.naver.com/saltynut/120042208214

728x90
Posted by kjun.kr
,