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?
Save up to 50% on our desktop apps during our Year End Sale!Save up to 50% on our desktop apps during our Year End Sale, including DisplayFusion, ClipboardFusion, FileSeek, LogFusion, TrayStatus, and VoiceBot!Save up to 50% on our desktop apps during our Year End Sale!

Span custom set of monitors unconditionally (Horizontally)

Description
This script will toggle spanning a custom group of horizontally arranged monitors.
Language
C#.net
Minimum Version
Created By
Dkyndt
Contributors
Keith Lammers (BFS)
Date Created
4d ago
Date Last Modified
4d ago

Scripted Function (Macro) Code

using System;
using System.Drawing;

// This script is based on Keith Lammers' original script.BFS.
// This script will toggle spanning a custom group of horizontally arranged monitors.
// Specify the monitor IDs from left-to-right in the monitorsToSpan array on line 14.
// Each time the script runs, it spans the window across the specified monitors.

public static class DisplayFusionFunction
{
    public static void Run(IntPtr windowHandle)
    {
        // Specify the monitors you want to span here
        // Ensure the monitor IDs are entered from left-to-right.
        uint[] monitorsToSpan = { 2, 3 };

        // Calculate the total size of the spanned window
        // Initialize with the first monitor's work area.
        Rectangle leftMonitorWorkArea = BFS.Monitor.GetMonitorWorkAreaByID(monitorsToSpan[0]);
        int windowWidth = 0; // Total width of all monitors in the span
        int windowHeight = leftMonitorWorkArea.Height; // Height will be the smallest height among the monitors

        // Iterate through each specified monitor to sum up the widths and find the smallest height
        foreach (uint monitorID in monitorsToSpan)
        {
            Rectangle monitorWorkArea = BFS.Monitor.GetMonitorWorkAreaByID(monitorID);
            windowWidth += monitorWorkArea.Width; // Add the monitor's width to the total
            if (monitorWorkArea.Height < windowHeight)
            {
                windowHeight = monitorWorkArea.Height; // Update to the smallest height encountered
            }
        }

        // Determine the top-left corner position of the spanned window
        int windowLocationX = leftMonitorWorkArea.X;
        int windowLocationY = leftMonitorWorkArea.Y;

        // Define the calculated size and position for the spanned window
        Rectangle calculatedSize = new Rectangle(windowLocationX, windowLocationY, windowWidth, windowHeight);

        // Always span the window to the calculated size
        BFS.Window.SetSizeAndLocation(windowHandle, calculatedSize.X, calculatedSize.Y, calculatedSize.Width, calculatedSize.Height);
    }
}