/// <summary> /// Updates the screen coordinate positions of the window's four corners /// </summary> public void UpdateWindowPosition() { if (!WinWindowInterop.GetWindowPosition(Handle, out _windowPosition)) { throw new Exception("Failed to get window position."); } }
/// <summary> /// Centers the window in the middle of the primary monitor. The window remains in its current z-index (i.e. if it was /// not foregrounded before this call, it will still not be foregrounded, but when shown it will be in the center of the screen). /// </summary> public void CenterWindow() { UpdateWindowPosition(); int xPos = (Screen.Width / 2) - (Width / 2); int yPos = (Screen.Height / 2) - (Height / 2); WinWindowInterop.MoveWindow(Handle, xPos, yPos); UpdateWindowPosition(); }
/// <summary> /// Foregrounds the window to the top if not already /// </summary> /// <returns>true if foregrounding succeeded, false otherwise</returns> public bool SetForeground() { return(WinWindowInterop.SetWindowActive(Handle)); }