There are several things in your question that concern me ... first you want to draw your own border, and then adjust the client rectangle. This is really not possible because the client rectangle is determined when the window is moved. After defining a completely different paint message, he is responsible for drawing all non-client content. That way you can do what you offer; however, it will violate your current border color.
It would be a FAR eaiser to move all your controls from your form to a new Panel control and place it on the form. Now you can place this panel as if you were setting up the client area.
If you must begin your initial thought in order to change the client area of ββthe window, you must do the following:
private void AdjustClientRect(ref RECT rcClient) { rcClient.Left += 10; rcClient.Top += 10; rcClient.Right -= 10; rcClient.Bottom -= 10; } struct RECT { public int Left, Top, Right, Bottom; } struct NCCALCSIZE_PARAMS { public RECT rcNewWindow; public RECT rcOldWindow; public RECT rcClient; IntPtr lppos; } protected override void WndProc(ref Message m) { base.WndProc(ref m); const int WM_NCCALCSIZE = 0x0083; if (m.Msg == WM_NCCALCSIZE) { if (m.WParam != IntPtr.Zero) { NCCALCSIZE_PARAMS rcsize = (NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(NCCALCSIZE_PARAMS)); AdjustClientRect(ref rcsize.rcNewWindow); Marshal.StructureToPtr(rcsize, m.LParam, false); } else { RECT rcsize = (RECT)Marshal.PtrToStructure(m.LParam, typeof(RECT)); AdjustClientRect(ref rcsize); Marshal.StructureToPtr(rcsize, m.LParam, false); } m.Result = new IntPtr(1); return; } }
source share