.net - 支持 DPI 和默认字体更改

标签 .net winforms dpi highdpi

所以我试图弄清楚 Form 的 AutoScaleMode 属性如何帮助支持带有字体或 DPI 的系统。这与我的工作开发机器不同。

从SDK:

AutoScaleMode Enumeration

public enum AutoScaleMode

None  
   Automatic scaling is disabled.    
Font   
   Controls scale relative to the dimensions of the 
   font the classes are using, which is typically the 
   system font.
Dpi    
   Controls scale relative to the display resolution. 
   Common resolutions are 96 and 120 DPI.


默认情况下,.NET 2.0 表单使用 AutoScaleMode.Font。

所以我在我的 Windows XP、Tahoma 8 pt、96 DPI 开发机器上设计了一个示例表单。然后我在一个
  • 14 pt Segoe UI 96 DPI 机器
  • 14 pt Segoe UI 150 DPI 机器

  • 结果并不令人鼓舞,正如您在此屏幕截图中所见:



    AutoScaleMode 属性并非旨在启用 .NET 表单以支持不同的字体或 DPI 设置。那又怎样支持不同字体和 DPI 设置的正确方法?

    最佳答案

    正确的方法是缩放控件、表单本身和其中的文本。这听起来很复杂,但布局控件(TableLayoutPanel 和 FlowLayoutPanel)与 AutoSize 属性相结合,大大降低了难度。

    关于.net - 支持 DPI 和默认字体更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/196606/

    相关文章:

    c# - .Net Dictionary<int,int> 在大约 6,000,000 个条目处出现内存不足异常

    .net - IO.File.GetLastAccessTime 关闭一小时

    c# - 如何使用 Enter 调用事件处理程序?

    c# - 无法将两个docker、一个数据库、一个.net core应用程序连接在一起

    c# - Entity Framework - 无效的列名 '*_ID"

    vb.net - DataGridViewRowsAdded 处理程序给出错误

    c# - 如何获取数据表中数据行的列值

    ios - 无法在 iOS 中找到图像的 DPI

    java - 屏幕密度高的设备上的大元素

    python - 在 Python TkInter 应用程序中检测 DPI/比例因子