Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Center Window and Align Right

Description
This script will move the window to the right side of the monitor and center it.
Language
C#.net
Minimum Version
Created By
Wee Hong KOH53892
Contributors
-
Date Created
Jul 2, 2021
Date Last Modified
Jul 2, 2021

Scripted Function (Macro) Code

using System;
using System.Drawing;

// The 'windowHandle' parameter will contain the window handle for the:
// - Active window when run by hotkey
// - Window Location target when run by a Window Location rule
// - TitleBar Button owner when run by a TitleBar Button
// - Jump List owner when run from a Taskbar Jump List
// - Currently focused window if none of these match

public static class DisplayFusionFunction
{

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

        uint primaryMonitorID = BFS.Monitor.GetPrimaryMonitorID();
        uint activeMonitorID = BFS.Monitor.GetMonitorIDByWindow(windowHandle);

        Rectangle windowRect = BFS.Window.GetBounds(windowHandle);
        Rectangle monitorRect = BFS.Monitor.GetMonitorWorkAreaByWindow(windowHandle);
        Rectangle primaryBounds = BFS.Monitor.GetPrimaryMonitorBounds();

        int iFinalWinX = monitorRect.Width / 2 + 20;
        int iFinalWinY = (primaryBounds.Height - windowRect.Height) / 2;

        if (primaryMonitorID != activeMonitorID) {
           iFinalWinX += primaryBounds.Width;
        }

        int iFinalWinW = monitorRect.Width / 2 - 40;
        int iFinalWinH = Convert.ToInt32(monitorRect.Height * 0.60);

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

    }

}