Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Move Window to Left or Right Side and Size 75% Width, 100% Height

Description
This script will move the window to the left side of the monitor and size it to 75%. If it's already there, then it will move it to the right side.
Language
C#.net
Minimum Version
Created By
Matt257
Contributors
-
Date Created
Mar 8, 2024
Date Last Modified
Mar 8, 2024

Scripted Function (Macro) Code

using System;
using System.Drawing;

public static class DisplayFusionFunction
{
    public static void Run(IntPtr windowHandle)
    {
        // Check to see if there was an error, if there was, exit the function
        if (windowHandle == IntPtr.Zero)
            return;

        // Get the position of the window in the monitor, and the current monitor
        Rectangle windowRect = BFS.Window.GetBounds(windowHandle);
        Rectangle monitorRect = BFS.Monitor.GetMonitorWorkAreaByWindow(windowHandle);

        int iFinalWinX = monitorRect.X;
        int iFinalWinY = monitorRect.Y;
        // Calculate 75% of the monitor's width
        int iFinalWinW = (int)(monitorRect.Width * 0.75);
        int iFinalWinH = monitorRect.Height;

        // Determine if the window is currently positioned on the left or right side
        if (windowRect.X == iFinalWinX && windowRect.Width == iFinalWinW)
        {
            // If on the left 75%, move it to the right 75%
            iFinalWinX = monitorRect.X + monitorRect.Width - iFinalWinW;
        }
        else
        {
            // Otherwise, move it to the left 75%
            iFinalWinX = monitorRect.X;
        }

        BFS.Window.SetSizeAndLocation(windowHandle, iFinalWinX, iFinalWinY, iFinalWinW, iFinalWinH);
    }
}