Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Version introduced: .NET 6
Remove high DPI settings from app.manifest and configure via
Application.SetHighDpiModeAPI orApplicationHighDpiModeproject property.
Windows Forms applications should specify application DPI-awareness via the application configuration or with the Application.SetHighDpiMode API.
Important
Starting with .NET 9, this warning has changed to WFO0003.
Workarounds
Using C#
Use the new bootstrap API by calling the ApplicationConfiguration.Initialize method before Application.Run().
class Program
{
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
The ApplicationConfiguration.Initialize method is generated when your app compiles, based on the settings in the app's project file. For example, look at the following <Application*> settings:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<ApplicationVisualStyles>true</ApplicationVisualStyles>
<ApplicationUseCompatibleTextRendering>false</ApplicationUseCompatibleTextRendering>
<ApplicationHighDpiMode>SystemAware</ApplicationHighDpiMode>
<ApplicationDefaultFont>Microsoft Sans Serif, 8.25pt</ApplicationDefaultFont>
</PropertyGroup>
</Project>
These settings generate the following method:
[CompilerGenerated]
internal static partial class ApplicationConfiguration
{
public static void Initialize()
{
global::System.Windows.Forms.Application.EnableVisualStyles();
global::System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
global::System.Windows.Forms.Application.SetHighDpiMode(HighDpiMode.SystemAware);
global::System.Windows.Forms.Application.SetDefaultFont(new Font(new FontFamily("Microsoft Sans Serif"), 8.25f, (FontStyle)0, (GraphicsUnit)3));
}
}
Using Visual Basic
Visual Basic operates a little differently than C# at the moment. The project file settings are required for Visual Studio to detect the application settings, but you must also configure the settings in the project's property page Application > Application Framework (which affects the My Project\Application.myapp file) or in the application startup events.
Important
Font isn't settable in the project properties.
The following code example demonstrates handling the ApplyApplicationDefaults event to configure the default font and HighDPI mode:
Imports Microsoft.VisualBasic.ApplicationServices
Namespace My
Partial Friend Class MyApplication
Private Sub MyApplication_ApplyApplicationDefaults(sender As Object, e As ApplyApplicationDefaultsEventArgs) Handles Me.ApplyApplicationDefaults
e.Font = New Font("Microsoft Sans Serif", 8.25)
e.HighDpiMode = HighDpiMode.SystemAware
End Sub
End Class
End Namespace
Manage the warning
Suppress the warning with either of the following methods:
Set the severity of the rule in the .editorConfig file.
[*.{cs,vb}] dotnet_diagnostic.WFAC010.severity = noneFor more information about editor config files, see Configuration files for code analysis rules.
Add the following
PropertyGroupto your project file:<PropertyGroup> <NoWarn>$(NoWarn);WFAC010</NoWarn> </PropertyGroup>Suppress in code with the
#pragma warning disable WFAC010directive.
.NET Desktop feedback