Report Viewer - scaling issue with system DPI change

后端 未结 2 1248
暖寄归人
暖寄归人 2021-01-12 15:04

I have a Winforms application (in Visual Studio 2010) that contains a Report Viewer control that previews and prints an A4 size report.

One user has his Windows font

2条回答
  •  旧时难觅i
    2021-01-12 16:02

    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.

提交回复
热议问题