/// <summary> /// Paint the border /// </summary> /// <param name="m"></param> private void WMNCPaint(ref Message m) { IntPtr hDC = NativeWindowCommon.GetWindowDC(m.HWnd); if (hDC != IntPtr.Zero) { IntPtr hrgnWindow = IntPtr.Zero; IntPtr hrgnClient = IntPtr.Zero; try { Rectangle rect = new Rectangle(1, 1, Width - 2, Height - 2); hrgnWindow = NativeWindowCommon.CreateRectRgn(0, 0, Width, Height); hrgnClient = NativeWindowCommon.CreateRectRgn(rect.Left, rect.Top, rect.Right, rect.Bottom); //Creates the union of two combined regions except for any overlapping areas. NativeWindowCommon.CombineRgn(hrgnWindow, hrgnWindow, hrgnClient, NativeWindowCommon.RGN_XOR); NativeWindowCommon.SelectClipRgn(hDC, hrgnWindow); using (Graphics g = Graphics.FromHdc(hDC)) { g.Clear(VisualStyleInformation.TextControlBorder); } m.Result = IntPtr.Zero; } finally { NativeWindowCommon.ReleaseDC(m.HWnd, hDC); if (hrgnWindow != IntPtr.Zero) { NativeWindowCommon.DeleteObject(hrgnWindow); } if (hrgnClient != IntPtr.Zero) { NativeWindowCommon.DeleteObject(hrgnClient); } } } }