Skip to content

Instantly share code, notes, and snippets.

@sunnyone
Last active August 29, 2015 14:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sunnyone/aaa2aef559ae7b765be5 to your computer and use it in GitHub Desktop.
Save sunnyone/aaa2aef559ae7b765be5 to your computer and use it in GitHub Desktop.
A script sharpens PowerShell ISE
# Install (simple way)
# Write this code to "%USERPROFILE%\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1"
# Install (module way)
# Place this script to "%USERPROFILE\Documents\WindowsPowerShell\Modules\UseLayoutRounding\UseLayoutRounding.psm1" and
# write "Import-Module UseLayoutRounding" to Microsoft.PowerShellISE_profile.ps1
Add-Type -TypeDefinition @"
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
public static class UseLayoutRounding
{
public static void Setup(object psISE)
{
var host = psISE.GetType().Assembly.GetType("Microsoft.Windows.PowerShell.Gui.Internal.PSGInternalHost");
var mainWindowField = host.GetField("mainWindow", BindingFlags.NonPublic | BindingFlags.Static);
var mainWindow = mainWindowField.GetValue(null);
var useLayoutRoudingMethod = mainWindow.GetType().GetProperty("UseLayoutRounding").GetSetMethod();
var syncCtxField = host.GetField("synchronizationContext", BindingFlags.NonPublic | BindingFlags.Static);
var syncCtx = (SynchronizationContext) syncCtxField.GetValue(null);
syncCtx.Post(x =>
{
useLayoutRoudingMethod.Invoke(mainWindow, new object[] {true});
}, null);
}
}
"@
[UseLayoutRounding]::Setup($psISE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment