问题描述
我无法使我的应用程序感知DPI。 在app.manifest中,我没有评论:
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
<appSettings>
<add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />
</appSettings>
我在关注以下问题和回应 Make vb.net application DPI aware 和 https://www.telerik.com/blogs/winforms-scaling-at-large-dpi-settings-is-it-even-possible-
我的应用程序具有带有单个用户控件的单个表单。在每一个我尝试使用AutoScaleMode来运行应用程序的各种设置中:无,Dpi,字体,继承(它们默认为字体)。我使用的是笔记本电脑出厂时的原始显示器。
在每种情况下,e.graphics.dpix和e.graphics.dpiy(其中e为PaintEventArgs)为96.0。应该是128.0 = 1920像素/ 15英寸和128.0 = 1080 / 8.4375英寸。
我想念什么?
解决方法
这是部分解决方案。
要在屏幕上绘画,请设置Graphics.PageUnit = GraphicsUnit.Point(默认值为GraphicsUnit.Display)。
(我还没有弄清楚如何在不合并DPI的情况下自动调整正在绘制的UserControl的大小。)
要进行打印,请使用Graphics.PageUnit = GraphicsUnit.Pixel。
' printing
dim gs as Drawing2D.GraphicsState = e.Graphics.Save
Try
e.Graphics.PageUnit = GraphicsUnit.Pixel
dim DpiX as Single = e.Graphics.DpiX
dim DpiY as Single = e.Graphics.DpiY
DoPrinting(e.Graphics,DpiX,DpiY) ' this is where you implement the code to draw your page
Catch ex as Exception
Finally
e.Graphics.Restore(gs)
End Try
' painting to screen
dim gs as Drawing2D.GraphicsState = e.Graphics.Point
Try
e.Graphics.PageUnit = GraphicsUnit.Pixel
dim DpiX as Single = 128.0! ' your value may vary; to find out,divide
dim DpiY as Single = 128.0! ' physical size of screen by screen resolution
DoPrinting(e.Graphics,DpiY) ' this is where you implement the code to paint to screen
Catch ex as Exception
Finally
e.Graphics.Restore(gs)
End Try