You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET中app.config与app.manifest的区别(WinForms项目场景)

Hey there! Let's break down the key differences between WinForms and other .NET project types (like WPF) when it comes to high-DPI settings targeting Windows 10 Creators Update, especially around those configuration files you're editing.

WinForms vs. Other .NET Projects: High-DPI Differences for Windows 10 Creators Update

Core DPI Awareness Models

  • WinForms: Historically had limited high-DPI support, so you need to explicitly opt into modern DPI awareness for the Creators Update. The recommended mode here is Per-Monitor DPI Awareness v2, though System DPI Awareness is also an option. WinForms relies heavily on configuration files + code-level tweaks (like handling DpiChanged events) to get right.
  • WPF/Modern .NET Projects: WPF has built-in DPI awareness by default (using System DPI Awareness out of the box). Enabling Per-Monitor v2 for Creators Update is more streamlined, and its vector-based layout engine means fewer scaling glitches without extra code fixes compared to WinForms.

Key Configuration File Differences

Assuming you're working with the application manifest and app.config (the two most common files for DPI settings):

  • Application Manifest:
    • For WinForms: You must add specific <dpiAware> and <dpiAwareness> elements to declare your DPI mode. For Creators Update's Per-Monitor v2, the entry looks like this:
      <application xmlns="urn:schemas-microsoft-com:asm.v3">
        <windowsSettings>
          <dpiAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true/PM</dpiAware>
          <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
        </windowsSettings>
      </application>
      
      Skip this, and WinForms will fall back to blurry legacy scaling on high-DPI displays.
    • For WPF: The manifest entry is similar, but WPF respects it natively. You won't need as many workarounds since its layout scales smoothly by default.
  • app.config:
    • For WinForms: You need to add the System.Windows.Forms.ApplicationConfigurationSection (only applicable to WinForms) to enable .NET Framework 4.7+ high-DPI features required for Creators Update support:
      <configuration>
        <System.Windows.Forms.ApplicationConfigurationSection>
          <add key="DpiAwareness" value="PerMonitorV2" />
          <add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />
        </System.Windows.Forms.ApplicationConfigurationSection>
      </configuration>
      
      This tells WinForms to use modern DPI APIs and auto-resize controls where possible.
    • For WPF: app.config doesn't require these WinForms-specific sections. WPF uses its own native DPI handling, with most adjustments done via the manifest or targeted code.

WinForms-Specific Notes for Your Project

Since you're focused on a WinForms project:

  • You must target .NET Framework 4.7 or higher to access the modern DPI APIs needed for Creators Update.
  • Some legacy controls (like DataGridView) might still have scaling issues even with config settings—you may need to handle DpiChanged events manually to adjust sizes or fonts.
  • Set AutoScaleMode.Dpi on your forms, and test each control's behavior across different DPI levels to catch edge cases.

Quick Recap

The config changes you're making are specific to WinForms. The manifest settings are partially shared with other project types, but the app.config entries for System.Windows.Forms.ApplicationConfigurationSection are exclusive to WinForms projects. You don't need to worry about these affecting non-WinForms codebases.

内容的提问来源于stack exchange,提问作者Chris K

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:34:57