internal static Rectangle TranslateClientRectangleToXClientRectangle (Hwnd hwnd, Control ctrl)
{
/*
* If this is a form with no window manager, X is handling all the border and caption painting
* so remove that from the area (since the area we set of the window here is the part of the window
* we're painting in only)
*/
Rectangle rect = hwnd.ClientRect;
Form form = ctrl as Form;
CreateParams cp = null;
if (form != null)
cp = form.GetCreateParams ();
if (form != null && (form.window_manager == null && !cp.IsSet (WindowExStyles.WS_EX_TOOLWINDOW))) {
Hwnd.Borders borders = Hwnd.GetBorders (cp, null);
Rectangle xrect = rect;
xrect.Y -= borders.top;
xrect.X -= borders.left;
xrect.Width += borders.left + borders.right;
xrect.Height += borders.top + borders.bottom;
rect = xrect;
}
if (rect.Width < 1 || rect.Height < 1) {
rect.Width = 1;
rect.Height = 1;
rect.X = -5;
rect.Y = -5;
}
return rect;
}