且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Windows窗体在Windows 10操作系统的图形问题

更新时间:2023-08-23 09:08:34

修改

虽然我以前使用了 SetProcessDPIAware 的方法来解决问题,但阅读说明使用前:

While I previously used the SetProcessDPIAware method to solve the problem, but read the note before use:

注意

SetProcessDPIAware 如有可能的竞争条件,如果一个DLL缓存DPI在初始化过程中设置。为此,建议DPI感知通过应用程序(.exe)的表现,而不是通过调用 SetProcessDPIAware

SetProcessDPIAware is subject to a possible race condition if a DLL caches dpi settings during initialization. For this reason, it is recommended that dpi-aware be set through the application (.exe) manifest rather than by calling SetProcessDPIAware.

SetProcessDPIAware 仅适用于在需求部分中指定的
操作系统使用。此方法
可以具有在操作
系统的后续版本意外行为。使用 SetProcessDpiAwareness 来代替。

SetProcessDPIAware is available for use only in the operating systems specified in the Requirements section. This method may have unexpected behavior in subsequent versions of the operating system. Use SetProcessDpiAwareness instead.

的DLL应该接受宿主进程的DPI设置,而不是
调用 SetProcessDPIAware 自己。要正确设置,dpiAware
应该被指定为应用程序文件(.exe)清单的一部分。

DLLs should accept the dpi setting of the host process rather than call SetProcessDPIAware themselves. To be set properly, dpiAware should be specified as part of the application (.exe) manifest.

您可以使用的 SetProcessDPIAware() 显示您的主要形式将自己的应用DPI感知和阻止Windows扩展应用程序之前方法。你也应该检查Windows版本要大于或等于Vista的:


You can use SetProcessDPIAware() method before showing your main form to set your application dpi aware and prevent windows from scaling the application. Also you should check the windows version to be greater than or equals to vista:

static class Program
{
    [DllImport("user32.dll", SetLastError = true)]
    static extern bool SetProcessDPIAware();

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        if (Environment.OSVersion.Version.Major >= 6)
            SetProcessDPIAware();

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(true);
        Application.Run(new Form1());
    }
}