winform 動態修改ClientRectangle

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            switch (m.Msg)
            {
                case 0x0083://WM_NCCALCSIZE
                    AdjustClientRect(ref m);
                    break;
            }
        }

        protected void AdjustClientRect(ref Message m)
        {
            if (m.WParam != IntPtr.Zero)
            {
                var rcsize =
                    (NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(NCCALCSIZE_PARAMS));
                AdjustClientRect(ref rcsize.rcNewWindow);
                Marshal.StructureToPtr(rcsize, m.LParam, false);
            }
            else
            {
                var rcsize = (RECT)Marshal.PtrToStructure(m.LParam, typeof(RECT));
                AdjustClientRect(ref rcsize);
                Marshal.StructureToPtr(rcsize, m.LParam, false);
            }
            m.Result = IntPtr.Zero;
        }

       protected void AdjustClientRect(ref RECT rcClient)
        {
            rcClient.Left += 2;
            rcClient.Top += 2;
            rcClient.Right -= 2;
            rcClient.Bottom -= 2;
        }

        public struct RECT
        {
            /// <exclude/>
            public int Left;
            /// <exclude/>
            public int Top;
            /// <exclude/>
            public int Right;
            /// <exclude/>
            public int Bottom;
        }

        public struct NCCALCSIZE_PARAMS
        {
            public RegionEx.RECT rcNewWindow;
            public RegionEx.RECT rcOldWindow;
            public RegionEx.RECT rcClient;
            IntPtr lppos;
        }

 

發佈了6 篇原創文章 · 獲贊 4 · 訪問量 8656
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章