【问题标题】:My Visual Studio 2013 applications have blurry fonts when running on Windows 10我的 Visual Studio 2013 应用程序在 Windows 10 上运行时字体模糊
【发布时间】:2015-11-05 18:07:23
【问题描述】:

升级到 Windows 10 后,我的 Visual Studio 2013 表单在运行时看起来很模糊,并且与 Visual Studio 2013 在设计模式下所描绘的样式不同。

我尝试安装 Visual Studio 2015,但模糊效果还是一样。

还有许多其他变化,例如取消 3D 按钮。

【问题讨论】:

  • 一些图片和复制器怎么样?
  • 还添加了图片,很高兴知道为什么投反对票?
  • 点击表单并转到属性找到 AutoScalMode 并将其更改为 DPI。看看这是否有所作为。
  • 感谢您的建议,但麻烦并没有消失,但它确实修复了计算按钮截断。如果您查看设计视图,则计算按钮单词“Calculate”在运行模式下正好适合按钮,该单词被截断。

标签: windows winforms visual-studio


【解决方案1】:

与其说是 Windows 10,不如说是 DPI 的变化。检查新安装的 Windows 10 中的 DPI 设置。

Check Windows 10 DPI

如果超过 100%,那么这就是您的应用程序模糊的原因。

查看 DPI Aware Windows Forms 应用程序。

DPI-Aware

基本上,一旦超过 125%,Windows 默认会通过让应用程序将其输出渲染到位图并将该位图绘制到屏幕来接管 UI 的缩放。该位图的重新缩放使文本看起来很模糊。

【讨论】:

  • 我刚查了一下,设置为100%。
  • 您描述的问题我能够找到您的标签模糊但表单标题清晰的确切行为。我给出的答案是在这种情况下的修复。
  • 是的,我的 Nvidia 驱动程序是最新的,尽管 nvidia 控制面板中有一条说明他们正在与 Microsoft 密切合作解决 Direct x 问题。
【解决方案2】:

显然这个问题是从 Windows 8 开始的,我像瘟疫一样避免了它。
这是我找到的解决方案:

转到Project > Add New Item > Application Manifest File 添加清单。

对于 Visual Studio 2015 及更高版本,您可以简单地取消注释此代码:

<application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
        <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
    </windowsSettings>
</application>

在旧版本的 Visual Studio 中,您需要自己添加此代码,因为它不会自动出现在清单中。

【讨论】:

  • 你在哪里找到的?我找不到它。这是否解决了模糊问题而无需将 UI 更改为小?
  • 这个答案不清楚。要获得更好的答案,请参阅:stackoverflow.com/questions/13228185/…
【解决方案3】:

Re:Windows 10 中的模糊表单。

我有 Windows 8.1 (OEM)。我所有的形式都清晰明了。我更新到 Windows 10,我的表单很模糊。我也使用 VBScript,而且我的 MsgBox 文本也很模糊。

我使用 125% 的屏幕放大率。我阅读的几个帮助表明,当大小设置为 100% 时,模糊性消失了。我也发现这是真的,但我想使用 125%。

我的笔记本电脑是德文的,所以我不知道所有的英文术语。我会尽力解释我的所作所为。

  1. 在开始页面中,我选择了设置(???--直接在开/关上方)
  2. 我选择了系统 (???)
  3. 我选择了屏幕 (???)
  4. 我没有使用 125% 预设,而是选择了扩展设置 (???)
  5. 我为文本和其他元素选择了扩展大小更改 (???)
  6. 我点击了用户定义缩放 (???) 并手动设置为 125%。

成功了!!!

【讨论】:

    【解决方案4】:

    This solution 为我工作。

    在 Windows 设置中应用所需的字体大小后(例如 125% DPI,我将其与 125% 一起使用)> 打开记事本,将其粘贴到其中:

    REG ADD "HKCU\Control Panel\Desktop" /v DpiScalingVer /t REG_DWORD /d 0x00001018 /f
    REG ADD "HKCU\Control Panel\Desktop" /v Win8DpiScaling /t REG_DWORD /d 0x00000001 /f
    REG ADD "HKCU\Control Panel\Desktop" /v LogPixels /t REG_DWORD /d 0x00000078 /f
    

    然后将其保存为 .cmd 在您的 HDD 上某处 → 打开本地地面策略编辑器(搜索栏中的 gpedit.msc)→ 在用户配置中(我正在用我的语言翻译它,因此翻译差异可能很小)→转到Windows设置→脚本(登录/注销)→在右侧窗口中双击登录以将其打开(因为我们希望每次登录时都应用它)→在脚本选项卡中,选择添加→然后在新窗口选择浏览器→导航到您保存cmd文件的位置并选择它→然后只需按确定→应用→确定→然后注销/重新启动您的电脑→登录添加此脚本后首次添加到您的帐户,以便应用它→如果它不起作用,请再次注销/重新启动,从现在开始它应该每次都可以工作(对我有用)。

    【讨论】:

      【解决方案5】:

      调用外部函数在整个应用程序中设置它。没有比这更容易的了:

       [STAThread]
          static void Main()
          {
              **SetProcessDPIAware();** //THIS
              Application.EnableVisualStyles();
              Application.SetCompatibleTextRenderingDefault(false);
              Application.Run(new Form1());
          }
      
          //ADD THESE TWO LINES !!
          [System.Runtime.InteropServices.DllImport("user32.dll")]
          private static extern bool SetProcessDPIAware();
      

      【讨论】:

        【解决方案6】:

        解决这个问题:

        1. 转到表单设计器,然后选择您的表单(通过单击其标题栏)
        2. F4打开属性窗口
        3. 选择AutoScaleMode 属性并将其从字体(默认)更改为Dpi。

        【讨论】:

          【解决方案7】:

          解决 VS 2013 开发的应用程序不具备 DPI 感知能力导致的 windows 10 运行模式下字体模糊(设计模式下清晰):

          (1)在Module.vb中,在顶部添加如下代码:

             Imports System.Runtime.InteropServices
              Module Module1
                  Public Declare Function SetProcessDpiAwarenessContext Lib "user32.dll" (ByVal dpiFlag As Integer) As Boolean
                  Public Declare Function SetProcessDpiAwareness Lib "SHCore.dll" (ByVal awareness As PROCESS_DPI_AWARENESS) As Boolean
                  Public Declare Function SetProcessDPIAware Lib "user32.dll" () As Boolean
              
                  Friend Enum PROCESS_DPI_AWARENESS
                      Process_DPI_Unaware = 0
                      Process_System_DPI_Aware = 1
                      Process_Per_Monitor_DPI_Aware = 2
                  End Enum
              
                  Friend Enum DPI_AWARENESS_CONTEXT
                      DPI_AWARENESS_CONTEXT_UNAWARE = 16
                      DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = 17
                      DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = 18
                      DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = 34
                  End Enum
              
                 
                  Public Sub Main()
                      Application.EnableVisualStyles()
                      Dim s() As String = System.Runtime.InteropServices.RuntimeInformation.OSDescription.Split(" ")
                      Dim OSver As String = s(2)
                      Dim curVer As New Version()
                      If Version.TryParse(OSver, curVer) Then
                          'Note: the three of the following methods work with Windows 10, however SetProcessDpiAwarenessContext is the best
                          If curVer >= New Version(6, 3, 0) Then ' win 8.1 added support for per monitor dpi
                              If curVer >= New Version(10, 0, 15063) Then ' win 10 creators update added support for per monitor v2
                                  SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)
                              Else
                                  SetProcessDpiAwareness(PROCESS_DPI_AWARENESS.Process_Per_Monitor_DPI_Aware)
                              End If
                          Else
                              SetProcessDPIAware()
                          End If
                          Debug.Print(curVer.ToString)
                      End If
                      Application.SetCompatibleTextRenderingDefault(False)
                      Application.Run(Form1)
                  End Sub
          End Module
          

          (2) 在项目属性->应用程序中,取消选中“启用应用程序框架” '并选择启动对象为“Sub Main”

          以下解决方案适用于 VS 2017: 通过 Project Properties->Application->View Windows Settings 打开 app.mainfest 将 Windows-10 兼容性代码添加到 app.mainfest 块内

          <!-- Windows 10 compatibility -->
                <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
          

          同样在block后面添加如下代码

          <application xmlns="urn:schemas-microsoft-com:asm.v3">
              <windowsSettings>
                <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
              </windowsSettings>
            </application>
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-04-22
            • 1970-01-01
            • 1970-01-01
            • 2020-01-24
            • 1970-01-01
            相关资源
            最近更新 更多