使用Winforms应用程序的DPI问题 [英] DPI Issue with Winforms application

查看:128
本文介绍了使用Winforms应用程序的DPI问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对winforms应用程序的DPI问题提出了疑问。

I got a question about DPI issue with winforms applications.

我有一个winforms C#应用程序,使用VS 2013使用.NET 4.5.2构建。我们的许多客户都在使用Window 8或8.1和Windows 10,其中一些人抱怨笔记本电脑和大显示器之间切换时的DPI问题。要解决这个
,我已将以下部分添加到我的清单文件中:

I am having a winforms C# application, built with .NET 4.5.2 using VS 2013. Many of our customers are using Window 8 or 8.1 and Windows 10 and some of them are complaining about the DPI issue when they switch between laptop and big monitors. To solve this I have added the below section to my manifest file:

< windowsSettings >

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; <! - Per Monitor V1 [OS> = Windows 8.1]

         ;值:False,True,Per-monitor,True / PM
- >

        < dpiAware
xmlns = " http://schemas.microsoft.com/SMI/2005/WindowsSettings " >

          true / PM

      ;&NBSP;&NBSP; < / dpiAware >

  ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; <! - Per Monitor V1 [OS> = Windows 10周年更新(1607,10.0.14393) ,
Redstone 1)]

     ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;值:Unaware,System,PerMonitor
- >

        <! - Per Monitor V2 [OS> = Windows 10 Creators Update(1703,10.0.15063) ,
Redstone 2)]

   ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;值:PerMonitorV2
- >

        < dpiAwareness
xmlns = " http://schemas.microsoft.com/SMI/2016/WindowsSettings " >

          PerMonitorV2,PerMonitor

       ;&NBSP;&NBSP; < / dpiAwareness >

< ; / windowsSettings >

但仍有一些问题没有解决。我们可以看到一些用户控件的问题,也可以从我们的应用程序创建OLE对象到MS字(没有正确获取对象的大小)。

But still some issues are not solved. We could see issues with some user controls and also while creating OLE objects from our app to MS word (not getting the size of the objects properly).

我知道这个问题已得到解决使用.NET 4.7但不幸的是我们今年没有升级计划。您能否建议我可以遵循一些修复或文件来解决这个问题?谢谢。

I understand that this issue has been addressed with .NET 4.7 but unfortunately we don’t have a plan to upgrade this year. Could you please suggest some fixes or documents that I could follow to fix this? Thank you.

推荐答案

嗨BKoshy,

Hi BKoshy,

尝试设置 AutoScaleMode 属性为
Dpi 而非字体:

Try to set the AutoScaleMode property of your form to Dpi instead of Font:

然后在Program.cs中更改一些代码:

Then change some code in the Program.cs:

class Program
{
    [STAThread]
    static void Main()
    {
        if (Environment.OSVersion.Version.Major >= 6)
            SetProcessDPIAware();

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

    [System.Runtime.InteropServices.DllImport("user32.dll")]
    private static extern bool SetProcessDPIAware();
}

问候,

Stanly


这篇关于使用Winforms应用程序的DPI问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆