Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

Center Window and Align Left

Description
This script will move the window to the left 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 = 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);

    }

}