示例#1
0
        /// <summary>
        /// Centers the provided window in the application host.
        /// </summary>
        /// <param name="hWnd">Handle to the window to be centered.</param>
        /// <param name="size">Size used to center the window.</param>
        protected void CenterWindow(IntPtr hWnd, Size size)
        {
            var bounds = new NativeMethods.RECT();

            NativeMethods.GetWindowRect(hWnd, ref bounds);

            int width = bounds.right - bounds.left;
            int height = bounds.bottom - bounds.top;

            NativeMethods.MoveWindow(
                hWnd,
                (size.Width - width) / 2,
                (size.Height - height) / 2,
                width,
                height,
                true
            );
        }
示例#2
0
 public static extern bool GetWindowRect(IntPtr hWnd, [In, Out] ref NativeMethods.RECT rect);