Login / Register
▼
Binary Fortress
Binary Fortress Software
CheckCentral
ClipboardFusion
CloudShow
DisplayFusion
FileSeek
HashTools
LogFusion
Notepad Replacer
Online Base64 Decoder
Online Base64 Encoder
Online JSON Formatter
ShellSend
TrayStatus
VoiceBot
WallpaperFusion
Window Inspector
More Apps...
DisplayFusion
CheckCentral
CloudShow
ClipboardFusion
FileSeek
VoiceBot
WallpaperFusion
Home
▼
Download
Download
Change Log
Download Beta
Beta Change Log
License (EULA)
▼
Features
Features
Incredible Desktop Wallpaper
Monitor Configuration
Monitor Splitting
Powerful Functions
Triggers
Multi-Monitor Taskbars
Useful Windows 10 Tweaks
Useful Windows 8 Tweaks
Windows Lock Screen
Multi-Monitor Screen Savers
Monitor Fading
Window Snapping
Window Management
Mouse Management
Alt+Tab Handler
Window Position Profiles
Desktop Icon Profiles
Remote Control
Available in dozens of Languages
Easy Administration
Free vs Pro
Purchase
Screenshots
Languages
▼
Help
Help Guide
FAQ
Discussions
Contact Us
Find My License
Mailing Address
Advanced Settings
Scripted Functions (Macros)
Display
Fusion
WARNING: You currently have Javascript disabled!
This website will not function correctly without Javascript enabled.
Title
Message
OK
Confirm
Yes
No
Center Window Ignoring Splits (run again to restore position)
Return to DisplayFusion Scripted Functions (Macros)
Description
Moves active window to center of monitor, overriding splits. When run again restores original position.
Position is stored per window, so any number of windows may be centered and then moved back to original position.
Set targetWidth to change window's width when centered (width is also restored when restoring position).
TIP: set targetWidth to 1920 to emulate the width of a borderless Full-HD window (very useful for ultra wides)
Language
C# (.Net)
Minimum Version
8.1.2+
Created By
Eurico Goncalves
Contributors
-
Date Created
Oct 11, 2017
Date Last Modified
Oct 11, 2017
Scripted Function (Macro) Code
Copy
Select All
Toggle Line Wrapping
using System; using System.Drawing; // Moves active window to center of monitor, ignoring splits // when run again (for same window) restores original position // position is stored per window, so any number of windows may be centered and then moved back to original position // set targetWidth to change window's width when centered (width is also restored when restoring position) // *** // TIP - set targetWidth to 1920 to emulate the width of a borderless FULL-HD window (very useful for ultra wides) // *** public static class DisplayFusionFunction { public static void Run(IntPtr windowHandle) { // general config string scriptID = "eg_move2center"; int targetMonitor = 0; // ignores splits: 0 - first monitor, 1 - second monitor, (...) int targetWidth = 0; // client size (i.e.: window's inner width); zero uses same width // we need an active window if (windowHandle == IntPtr.Zero) { BFS.Dialog.ShowMessageError("No active window found."); return; } // get an ID for window string windowID = BFS.Window.BuildWindowDebug(windowHandle); if (string.IsNullOrEmpty(windowID)) { BFS.Dialog.ShowMessageError("Failed to fetch a window ID."); return; } // no windowBounds stored? store them and move to center, otherwise restore previous bounds string storedBoundsKey = scriptID + "_stored_window_" + windowID; string storedBounds = BFS.ScriptSettings.ReadValue(storedBoundsKey); RectangleConverter rectConverter = new RectangleConverter(); // move to center and store original bounds if (string.IsNullOrEmpty(storedBounds)) { Rectangle[] monitorBounds = BFS.Monitor.GetMonitorBoundsNoSplits(); Rectangle windowBounds = BFS.Window.GetBounds(windowHandle); int primaryMonitorCenter = monitorBounds[targetMonitor].Width / 2; if (targetWidth > 0) { // let's get cient (inner) width, so that borders and/or paddings are added Rectangle clientBounds = BFS.Window.GetClientRect(windowHandle); targetWidth += (windowBounds.Width - clientBounds.Width); } int windowWidth = (targetWidth > 0) ? targetWidth : windowBounds.Width; bool windowMoved = BFS.Window.SetSizeAndLocation(windowHandle, primaryMonitorCenter - (windowWidth / 2), windowBounds.Top, windowWidth, windowBounds.Height); if (windowMoved) { // save original bounds to allow restoring original size and position BFS.ScriptSettings.WriteValue(storedBoundsKey, rectConverter.ConvertToString(windowBounds)); } // restore original bounds } else { Rectangle windowBounds = (Rectangle)rectConverter.ConvertFromString(storedBounds); bool windowMoved = BFS.Window.SetSizeAndLocation(windowHandle, windowBounds.Left, windowBounds.Top, windowBounds.Width, windowBounds.Height); if (windowMoved) { // reset storedBounds BFS.ScriptSettings.WriteValue(storedBoundsKey, ""); } } } }
Copyright © 2007-2021 Binary Fortress Software
•
News
•
Discussions
•
FAQ
•
Support
•
Privacy
•
ToS
•
Get DisplayFusion Merch