/// <summary> /// Converts ScreenAlignment to Offset. alignment depends on the window and the screen /// </summary> /// <param name="window">WPF window</param> /// <param name="screen">Windows.Forms.Screen</param> /// <param name="alignment"></param> /// <returns>offset</returns> public static Point?AlignmentToOffset(Window window, Screen screen, ScreenAlignment alignment) { if (screen == null) { return(null); } // can't send when window is maximized WindowState winState = window.WindowState; if (winState == WindowState.Maximized) { window.WindowState = WindowState.Normal; } var dpiRatio = getDPIRatio(); var point = AlignmentToOffsetLogic((int)(window.ActualWidth * dpiRatio.X), (int)(window.ActualHeight * dpiRatio.Y), screen.WorkingArea, alignment); if (winState == WindowState.Maximized) { window.WindowState = WindowState.Maximized; } return(point); }
public virtual void Align(Region parent) { ScreenAlignment.ManageTransformation(this.AddTransformation, parent, this.Region, this.Padding); if (Text != null) { Text.Align(this.Region); } }
/// <summary> /// Sends a window to the primary screen /// </summary> /// <param name="hwnd">window handle to send to primary screen</param> /// <param name="align">Screen alignment</param> /// <param name="extend">change screen topology to extended if /// current topology is not extend. if current topology is not on extend the function will fail</param> /// <returns>bool to indicate success and failure</returns> public static bool SendToPrimary(IntPtr hwnd, ScreenAlignment align) { Point?maybe_offset = AlignmentToOffset(hwnd, PrimaryScreen, align); if (maybe_offset == null) { return(false); } var offset = (Point)maybe_offset; return(SendToPrimary(hwnd, (int)offset.X, (int)offset.Y)); }
/// <summary> /// Sends a window to a screen /// </summary> /// <param name="hwnd">window handle</param> /// <param name="screen">screen to send the window to</param> /// <param name="align">Screen alignment</param> /// <returns>bool to indicate success and failure.</returns> public static bool SendToScreen(IntPtr hwnd, Screen screen, ScreenAlignment align) { var maybe_point = AlignmentToOffset(hwnd, screen, align); if (maybe_point == null) { return(false); } var point = (Point)maybe_point; return(SendToScreen(hwnd, screen, (int)point.X, (int)point.Y)); }
/// <summary> /// Sends a window to a screen /// </summary> /// <param name="window">to send to screen</param> /// <param name="screen">screen to send the window to</param> /// <param name="align">Screen alignment</param> /// <returns>bool to indicate success and failure.</returns> public static bool SendToScreen(Window window, Screen screen, ScreenAlignment align) { if (screen == null) { return(false); } var maybe_offset = AlignmentToOffset(window, screen, align); if (maybe_offset == null) { return(false); } Point offset = (Point)maybe_offset; return(SendToScreen(window, screen, (int)offset.X, (int)offset.Y)); }
/// <summary> /// Converts ScreenAlignment to Offset. alignment depends on the window and the screen /// </summary> /// <param name="hwnd">window handle</param> /// <param name="screen"></param> /// <param name="alignment"></param> /// <returns>offset</returns> public static Point?AlignmentToOffset(IntPtr hwnd, Screen screen, ScreenAlignment alignment) { if (screen == null) { return(null); } WINDOWINFO winInfo = new WINDOWINFO(); GetWindowInfo(hwnd, ref winInfo); int windowWidth = winInfo.Window.Right - winInfo.Window.Left; int windowHeight = winInfo.Window.Bottom - winInfo.Window.Top; var dpiRatio = getDPIRatio(); if (1.45 < dpiRatio.X && dpiRatio.X < 1.55 && 1.45 < dpiRatio.Y && dpiRatio.Y < 1.55) { windowWidth = (int)((double)windowWidth * dpiRatio.X); windowHeight = (int)((double)windowHeight * dpiRatio.Y); } return(AlignmentToOffsetLogic(windowWidth, windowHeight, screen.WorkingArea, alignment)); }
/// <summary> /// Sends a window to from primary screen to secondary or from secondary screen to primary screen. /// </summary> /// <param name="window">to send</param> /// <param name="align">Screen alignment</param> /// <param name="extend">change screen topology to extended if /// current topology is not extend. if current topology is not on extend the function will fail</param> /// <returns>bool to indicate success and failure. failure will denote when /// there aren't enough displays or the current screen topology is not extend /// and the extend mark is not set to true</returns> public static bool SwapScreen(Window window, ScreenAlignment align) { return SendToScreen(window, getOtherScreen(window), align); }
/// <summary> /// Sends a window to the secondary screen. /// </summary> /// <param name="hwnd">Window handle to send to secondary screen</param> /// <param name="align">Screen alignment</param> /// <param name="extend">change screen topology to extended. if current topology is not on extend the function will fail</param> /// <returns>bool to indicate success and failure. failure will denote when /// there aren't enough displays or the current screen topology is not extend /// and the extend mark is not set to true</returns> public static bool SendToSecondary(IntPtr hwnd, ScreenAlignment align) { return(SendToScreen(hwnd, SecondaryScreen, align)); }
/// <summary> /// Sends a window to from primary screen to secondary or from secondary screen to primary screen. /// </summary> /// <param name="hwnd">Window handle to send</param> /// <param name="align">Screen alignment</param> /// <param name="extend">change screen topology to extended if /// current topology is not extend. if current topology is not on extend the function will fail</param> /// <returns>bool to indicate success and failure. failure will denote when /// there aren't enough displays or the current screen topology is not extend /// and the extend mark is not set to true</returns> public static bool SwapScreen(IntPtr hwnd, ScreenAlignment align) { return(SendToScreen(hwnd, getOtherScreen(hwnd), align)); }
/// <summary> /// Sends a window to the primary screen /// </summary> /// <param name="hwnd">window handle to send to primary screen</param> /// <param name="align">Screen alignment</param> /// <param name="extend">change screen topology to extended if /// current topology is not extend. if current topology is not on extend the function will fail</param> /// <returns>bool to indicate success and failure</returns> public static bool SendToPrimary(IntPtr hwnd, ScreenAlignment align) { Point? maybe_offset = AlignmentToOffset(hwnd, PrimaryScreen, align); if (maybe_offset == null) return false; var offset = (Point)maybe_offset; return SendToPrimary(hwnd, (int)offset.X, (int)offset.Y); }
/// <summary> /// Sends a window to a screen /// </summary> /// <param name="window">to send to screen</param> /// <param name="screen">screen to send the window to</param> /// <param name="align">Screen alignment</param> /// <returns>bool to indicate success and failure.</returns> public static bool SendToScreen(Window window, Screen screen, ScreenAlignment align) { if (screen == null) return false; var maybe_offset = AlignmentToOffset(window, screen, align); if (maybe_offset == null) return false; Point offset = (Point)maybe_offset; return SendToScreen(window, screen, (int)offset.X, (int)offset.Y); }
/// <summary> /// Sends a window to from primary screen to secondary or from secondary screen to primary screen. /// </summary> /// <param name="hwnd">Window handle to send</param> /// <param name="align">Screen alignment</param> /// <param name="extend">change screen topology to extended if /// current topology is not extend. if current topology is not on extend the function will fail</param> /// <returns>bool to indicate success and failure. failure will denote when /// there aren't enough displays or the current screen topology is not extend /// and the extend mark is not set to true</returns> public static bool SwapScreen(IntPtr hwnd, ScreenAlignment align) { return SendToScreen(hwnd, getOtherScreen(hwnd), align); }
/// <summary> /// Sends a window to from primary screen to secondary or from secondary screen to primary screen. /// </summary> /// <param name="window">to send</param> /// <param name="align">Screen alignment</param> /// <param name="extend">change screen topology to extended if /// current topology is not extend. if current topology is not on extend the function will fail</param> /// <returns>bool to indicate success and failure. failure will denote when /// there aren't enough displays or the current screen topology is not extend /// and the extend mark is not set to true</returns> public static bool SwapScreen(Window window, ScreenAlignment align) { return(SendToScreen(window, getOtherScreen(window), align)); }
public UIResText(string caption, PointF position, float scale, Color color, Font font, ScreenAlignment justify) : base(caption, position, scale, color, font, CitizenFX.Core.UI.Alignment.Left) { TextAlignment = justify; }
/// <summary> /// Converts ScreenAlignment to Offset. alignment depends on the window and the screen /// </summary> /// <param name="windowWidth">width of the window</param> /// <param name="windowHeight">height of the window</param> /// <param name="screen"></param> /// <param name="alignment"></param> /// <returns>offset</returns> private static Point AlignmentToOffsetLogic(int windowWidth, int windowHeight, System.Drawing.Rectangle workingArea, ScreenAlignment alignment) { var offsetX = 0.0; var offsetY = 0.0; // center if (alignment.HasFlag(ScreenAlignment.Center)) { offsetX = (workingArea.Width / 2) - (windowWidth / 2); offsetY = (workingArea.Height / 2) - (windowHeight / 2); } // left & right if (alignment.HasFlag(ScreenAlignment.Left) && alignment.HasFlag(ScreenAlignment.Right)) { offsetX = (workingArea.Width / 2) - (windowWidth / 2); } // only left else if (alignment.HasFlag(ScreenAlignment.Left)) { offsetX = 0; } // only right else if (alignment.HasFlag(ScreenAlignment.Right)) { offsetX = workingArea.Width - windowWidth; } // top & bottom if (alignment.HasFlag(ScreenAlignment.Top) && alignment.HasFlag(ScreenAlignment.Bottom)) { offsetY = (workingArea.Height / 2) - (windowHeight / 2); } // only top else if (alignment.HasFlag(ScreenAlignment.Top)) { offsetY = 0; } // only bottom else if (alignment.HasFlag(ScreenAlignment.Bottom)) { offsetY = workingArea.Height - windowHeight; } return(new Point(offsetX, offsetY)); }
/// <summary> /// Sends the main window of a program to screen /// </summary> /// <param name="progName">program name</param> /// <param name="screen">Screen to send the window to</param> /// <param name="align">Screen alignment</param> /// <returns>bool to indicate success or failure.</returns> public static bool SendProgramsMainWindowToScreen(string progName, Screen screen, ScreenAlignment align) { if (screen == null) return false; var hwnds = getProcessWindowByName(progName); bool success = false; foreach (var hwnd in hwnds) success |= SendToScreen(hwnd, screen, align); return success; }
/// <summary> /// Sends the main window of a program to screen /// </summary> /// <param name="progName">program name</param> /// <param name="screen">Screen to send the window to</param> /// <param name="align">Screen alignment</param> /// <returns>bool to indicate success or failure.</returns> public static bool SendProgramsMainWindowToScreen(string progName, Screen screen, ScreenAlignment align) { if (screen == null) { return(false); } var hwnds = getProcessWindowByName(progName); bool success = false; foreach (var hwnd in hwnds) { success |= SendToScreen(hwnd, screen, align); } return(success); }
/// <summary> /// Converts ScreenAlignment to Offset. alignment depends on the window and the screen /// </summary> /// <param name="hwnd">window handle</param> /// <param name="screen"></param> /// <param name="alignment"></param> /// <returns>offset</returns> public static Point? AlignmentToOffset(IntPtr hwnd, Screen screen, ScreenAlignment alignment) { if (screen == null) return null; WINDOWINFO winInfo = new WINDOWINFO(); GetWindowInfo(hwnd, ref winInfo); int windowWidth = winInfo.Window.Right - winInfo.Window.Left; int windowHeight = winInfo.Window.Bottom - winInfo.Window.Top; var dpiRatio = getDPIRatio(); if (1.45 < dpiRatio.X && dpiRatio.X < 1.55 && 1.45 < dpiRatio.Y && dpiRatio.Y < 1.55) { windowWidth = (int)((double)windowWidth*dpiRatio.X); windowHeight = (int)((double)windowHeight*dpiRatio.Y); } return AlignmentToOffsetLogic(windowWidth, windowHeight, screen.WorkingArea, alignment); }
/// <summary> /// Converts ScreenAlignment to Offset. alignment depends on the window and the screen /// </summary> /// <param name="window">WPF window</param> /// <param name="screen">Windows.Forms.Screen</param> /// <param name="alignment"></param> /// <returns>offset</returns> public static Point? AlignmentToOffset(Window window, Screen screen, ScreenAlignment alignment) { if (screen == null) return null; // can't send when window is maximized WindowState winState = window.WindowState; if (winState == WindowState.Maximized) window.WindowState = WindowState.Normal; var dpiRatio = getDPIRatio(); var point = AlignmentToOffsetLogic((int)(window.ActualWidth*dpiRatio.X), (int)(window.ActualHeight*dpiRatio.Y), screen.WorkingArea, alignment); if (winState == WindowState.Maximized) window.WindowState = WindowState.Maximized; return point; }
/// <summary> /// Sends a window to a screen /// </summary> /// <param name="hwnd">window handle</param> /// <param name="screen">screen to send the window to</param> /// <param name="align">Screen alignment</param> /// <returns>bool to indicate success and failure.</returns> public static bool SendToScreen(IntPtr hwnd, Screen screen, ScreenAlignment align) { var maybe_point = AlignmentToOffset(hwnd, screen, align); if (maybe_point == null) return false; var point = (Point)maybe_point; return SendToScreen(hwnd, screen, (int)point.X, (int)point.Y); }
/// <summary> /// Sends a window to the secondary screen. /// </summary> /// <param name="window">to send to secondary screen</param> /// <param name="align">Screen alignment</param> /// <param name="extend">change screen topology to extended. if current topology is not on extend the function will fail</param> /// <returns>bool to indicate success and failure. failure will denote when /// there aren't enough displays or the current screen topology is not extend /// and the extend mark is not set to true</returns> public static bool SendToSecondary(Window window, ScreenAlignment align) { return SendToScreen(window, SecondaryScreen, align); }
/// <summary> /// Sends a window to the secondary screen. /// </summary> /// <param name="window">to send to secondary screen</param> /// <param name="align">Screen alignment</param> /// <param name="extend">change screen topology to extended. if current topology is not on extend the function will fail</param> /// <returns>bool to indicate success and failure. failure will denote when /// there aren't enough displays or the current screen topology is not extend /// and the extend mark is not set to true</returns> public static bool SendToSecondary(Window window, ScreenAlignment align) { return(SendToScreen(window, SecondaryScreen, align)); }
/// <summary> /// Sends all window of a program to a screen /// </summary> /// <param name="progName">program name</param> /// <param name="screen">screen to send the window to</param> /// <param name="align">Screen alignment</param> /// <returns>bool to indicate success or failure.</returns> public static bool SendProgramsWindowsToScreen(string progName, Screen screen, ScreenAlignment align) { if (screen == null) return false; var hwnds = getWindowHandlesFromProgramName(progName); if (hwnds.Length < 1) return false; var result = (from hwnd in hwnds select SendToScreen(hwnd, screen, align)).All(x => x == true); return result; }
/// <summary> /// Sends a window to the secondary screen. /// </summary> /// <param name="hwnd">Window handle to send to secondary screen</param> /// <param name="align">Screen alignment</param> /// <param name="extend">change screen topology to extended. if current topology is not on extend the function will fail</param> /// <returns>bool to indicate success and failure. failure will denote when /// there aren't enough displays or the current screen topology is not extend /// and the extend mark is not set to true</returns> public static bool SendToSecondary(IntPtr hwnd, ScreenAlignment align) { return SendToScreen(hwnd, SecondaryScreen, align); }
/// <summary> /// Sends all window of a program to a screen /// </summary> /// <param name="progName">program name</param> /// <param name="screen">screen to send the window to</param> /// <param name="align">Screen alignment</param> /// <returns>bool to indicate success or failure.</returns> public static bool SendProgramsWindowsToScreen(string progName, Screen screen, ScreenAlignment align) { if (screen == null) { return(false); } var hwnds = getWindowHandlesFromProgramName(progName); if (hwnds.Length < 1) { return(false); } var result = (from hwnd in hwnds select SendToScreen(hwnd, screen, align)).All(x => x == true); return(result); }
/// <summary> /// Converts ScreenAlignment to Offset. alignment depends on the window and the screen /// </summary> /// <param name="windowWidth">width of the window</param> /// <param name="windowHeight">height of the window</param> /// <param name="screen"></param> /// <param name="alignment"></param> /// <returns>offset</returns> private static Point AlignmentToOffsetLogic(int windowWidth, int windowHeight, System.Drawing.Rectangle workingArea, ScreenAlignment alignment) { var offsetX = 0.0; var offsetY = 0.0; // center if (alignment.HasFlag(ScreenAlignment.Center)) { offsetX = (workingArea.Width / 2) - (windowWidth / 2); offsetY = (workingArea.Height / 2) - (windowHeight / 2); } // left & right if (alignment.HasFlag(ScreenAlignment.Left) && alignment.HasFlag(ScreenAlignment.Right)) offsetX = (workingArea.Width / 2) - (windowWidth / 2); // only left else if (alignment.HasFlag(ScreenAlignment.Left)) offsetX = 0; // only right else if (alignment.HasFlag(ScreenAlignment.Right)) offsetX = workingArea.Width - windowWidth; // top & bottom if (alignment.HasFlag(ScreenAlignment.Top) && alignment.HasFlag(ScreenAlignment.Bottom)) offsetY = (workingArea.Height / 2) - (windowHeight / 2); // only top else if (alignment.HasFlag(ScreenAlignment.Top)) offsetY = 0; // only bottom else if (alignment.HasFlag(ScreenAlignment.Bottom)) offsetY = workingArea.Height - windowHeight; return new Point(offsetX, offsetY); }