Skip to content

Commit 7063c90

Browse files
committed
enable dpi aware
1 parent 66477b2 commit 7063c90

File tree

5 files changed

+94
-0
lines changed

5 files changed

+94
-0
lines changed

Source/Demo/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<System.Windows.Forms.ApplicationConfigurationSection>
4+
<add key="DpiAwareness" value="PerMonitorV2" />
5+
</System.Windows.Forms.ApplicationConfigurationSection>
6+
</configuration>

Source/Demo/Demo.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<UseWindowsForms>true</UseWindowsForms>
88
<ImplicitUsings>enable</ImplicitUsings>
99
<Platforms>AnyCPU;x64;x86</Platforms>
10+
<ApplicationManifest>app.manifest</ApplicationManifest>
1011
</PropertyGroup>
1112

1213
<ItemGroup>

Source/Demo/Form1.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ private void Form1_Load(object sender, EventArgs e)
2727
canvas.Bitmap = new Bitmap(Environment.GetCommandLineArgs()[1], true);
2828
}
2929

30+
31+
protected override void OnDpiChanged(DpiChangedEventArgs e)
32+
{
33+
base.OnDpiChanged(e);
34+
}
35+
3036
public static WicBitmapSource? FromBitmapSource(BitmapSource bmp)
3137
{
3238
if (bmp == null)

Source/Demo/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ static void Main()
1111
// To customize application configuration such as set high DPI settings or default font,
1212
// see https://aka.ms/applicationconfiguration.
1313
ApplicationConfiguration.Initialize();
14+
Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
1415
Application.Run(new Form1());
1516
}
1617
}

Source/Demo/app.manifest

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
3+
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
4+
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
5+
<security>
6+
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
7+
<!-- UAC Manifest Options
8+
If you want to change the Windows User Account Control level replace the
9+
requestedExecutionLevel node with one of the following.
10+
11+
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
12+
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
13+
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
14+
15+
Specifying requestedExecutionLevel element will disable file and registry virtualization.
16+
Remove this element if your application requires this virtualization for backwards
17+
compatibility.
18+
-->
19+
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
20+
</requestedPrivileges>
21+
</security>
22+
</trustInfo>
23+
24+
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
25+
<application>
26+
<!-- A list of the Windows versions that this application has been tested on
27+
and is designed to work with. Uncomment the appropriate elements
28+
and Windows will automatically select the most compatible environment. -->
29+
30+
<!-- Windows Vista -->
31+
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
32+
33+
<!-- Windows 7 -->
34+
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
35+
36+
<!-- Windows 8 -->
37+
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
38+
39+
<!-- Windows 8.1 -->
40+
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
41+
42+
<!-- Windows 10 -->
43+
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
44+
45+
</application>
46+
</compatibility>
47+
48+
<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
49+
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
50+
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
51+
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config.
52+
53+
Makes the application long-path aware. See https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation -->
54+
55+
<application xmlns="urn:schemas-microsoft-com:asm.v3">
56+
<windowsSettings>
57+
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
58+
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
59+
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
60+
</windowsSettings>
61+
</application>
62+
63+
64+
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
65+
<!--
66+
<dependency>
67+
<dependentAssembly>
68+
<assemblyIdentity
69+
type="win32"
70+
name="Microsoft.Windows.Common-Controls"
71+
version="6.0.0.0"
72+
processorArchitecture="*"
73+
publicKeyToken="6595b64144ccf1df"
74+
language="*"
75+
/>
76+
</dependentAssembly>
77+
</dependency>
78+
-->
79+
80+
</assembly>

0 commit comments

Comments
 (0)