Report Viewer - scaling issue with system DPI change

旧巷老猫 提交于 2019-12-01 04:26:16

I ran into the same problem. WinForms ReportViewer is already DPI aware and will do its own scaling. You just have to tell the system that your application is DPI aware so that the system doesn't try to scale it after.

Add a manifest to your application if you haven't already, then inside the tag, add the following:

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

You can also use an API function SetProcessDPIAware, but it is recommended against: http://msdn.microsoft.com/en-us/library/ms633543.aspx

As a complimentary answer to what @JoMan said (since I can't comment on his post) bear in mind that you can manually scale up the UI elements in your app relatively simply. So leave your application DPI aware (so that your system doesn't distort the printed results) as JOMan suggested. You could use something like this...

Using g As System.Drawing.Graphics = WindowsForm.CreateGraphics
 Dim sngScaleFactor As Single = 1
 Dim sngFontFactor As Single = 1 

 If (graphics.Dpix >= 96) Then
      sngScaleFactor = (graphics.Dpix / 96) - 0.25
      sngFontFactor = (graphics.Dpix / 96) - 0.25
 End If

 If WindowsForm.AutoScaleDimensions = WindowsForm.CurrentAutoScaleDimensions Then
            WindowsForm.Scale(sngScaleFactor)
            For Each child As Control In WindowsForm.Controls
                ScaleFontRecursively(child, sngFontFactor)
            Next
 End If
End Using

I'm sure many people will argue (rightly!) that you generally don't want to detect DPI and manually scale yourself, but the bug with the dpi autoscaling screwing up printed microsoft reports is still outstanding as of 2018, so this provides an easy work around.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!