Beispiel #1
0
        /// <include file='doc\CommonDialog.uex' path='docs/doc[@for="CommonDialog.MoveToScreenCenter"]/*' />
        /// <devdoc>
        ///     Centers the given window on the screen. This method is used by the default
        ///     common dialog hook procedure to center the dialog on the screen before it
        ///     is shown.
        /// </devdoc>
        internal static void MoveToScreenCenter(IntPtr hWnd)
        {
            NativeMethods.RECT r = new NativeMethods.RECT();
            UnsafeNativeMethods.GetWindowRect(new HandleRef(null, hWnd), ref r);
            Rectangle screen = Screen.GetWorkingArea(Control.MousePosition);
            int       x      = screen.X + (screen.Width - r.right + r.left) / 2;
            int       y      = screen.Y + (screen.Height - r.bottom + r.top) / 3;

            SafeNativeMethods.SetWindowPos(new HandleRef(null, hWnd), NativeMethods.NullHandleRef, x, y, 0, 0, NativeMethods.SWP_NOSIZE |
                                           NativeMethods.SWP_NOZORDER | NativeMethods.SWP_NOACTIVATE);
        }