Skip to content

Instantly share code, notes, and snippets.

@neuralpain
Created March 9, 2024 06:09
Show Gist options
  • Save neuralpain/45e3ca94c7e32f2d1b14fdf510aca62d to your computer and use it in GitHub Desktop.
Save neuralpain/45e3ca94c7e32f2d1b14fdf510aca62d to your computer and use it in GitHub Desktop.
Add DPI awareness to Powershell-run .Net Windows Forms
using assembly System.Windows.Forms
using namespace System.Windows.Forms
using namespace System.Drawing
#Enable visual styles
[Application]::EnableVisualStyles()
#Enable DPI awareness
$code = @"
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool SetProcessDPIAware();
"@
$Win32Helpers = Add-Type -MemberDefinition $code -Name "Win32Helpers" -PassThru
$null = $Win32Helpers::SetProcessDPIAware()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment