Processing Ajax...

Close Dialog


Close Dialog

Close Dialog

A recent AVG and Avast antivirus update is preventing DisplayFusion 9.9 from launching on some systems.
If you're running into this issue, please update to the latest DisplayFusion 10.0 Beta.

Center Window and Align Right

This script will move the window to the right side of the monitor and center it.
Minimum Version
Created By
Wee Hong KOH53892
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)

        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);