/// <summary> /// Calculates total width of control buttons (minimize, maximize, close). /// </summary> /// <param name="handle">Window handle.</param> /// <returns>Total width in pixels.</returns> private static int GetControlAreaWidth(IntPtr handle) { WindowStyle style = new WindowStyle(handle); int buttonCount = style.MaximizeBox || style.MinimizeBox ? 3 : 1; int controlButtonAverageWidth = ApiSystemMetrics.Get(SystemMetric.SM_CXSIZE); return(controlButtonAverageWidth * buttonCount); }
/// <summary> /// Get total computed width of control box area (minimize, maximize and close buttons). /// </summary> /// <returns>Total width in pixels.</returns> public int GetControlBoxWidth() { int controlBoxWidth = ApiSystemMetrics.GetControlBoxWidth(this.Handle); if (controlBoxWidth > 0) { return(controlBoxWidth); } // legacy OS int buttonCount = this.MaximizeBox || this.MinimizeBox ? 3 : 1; int controlButtonAverageWidth = ApiSystemMetrics.GetControlButtonWidth(); return(controlButtonAverageWidth * buttonCount); }