winforms icon indicating copy to clipboard operation
winforms copied to clipboard

Control printing test coverage

Open weltkante opened this issue 4 years ago • 0 comments

Is your feature request related to a problem? Please describe.

During PR review it was noted that there is likely little test coverage of printing support of Controls. Printers typically use higher DPI and it was unclear how this represents itself during control rendering. The behavior should be checked and if possible tests should be added.

The most common usage of printing functionality I am aware of is used in reporting, where WinForms UserControls can be printed into a report. Sometimes people also want to print out a form filled with values for documentation purposes. Printing is also used to generate PDF or XPS documents to be sent by mail, so is not restricted to physical printers.

Describe the solution you'd like and alternatives you've considered

  • add tests for covering Control.DrawToBitmap, both for general functionality and also covering DPI behavior. Preliminary testing indicates that Control.DrawToBitmap currently ignores image DPI.

  • examine how WM_PRINT / WM_PRINTCLIENT scenarios are propagating DPI when rendering to a printer HDC (e.g. by calling PrintDlgEx to select a printer in a local test environment and use PrintWindow to trigger a WM_PRINT, or maybe send messages directly).

    Depending on how WinForms reacts on native messages with a printer HDC it may not be necessary to have dedicated tests, if it also ignores DPI like DrawToBitmap does then test coverage through the latter might be enough. If drawing to a printer HDC actually preserves DPI then there should be tests added to provide coverage and prevent regressions. It might be possible to use the XPS printing driver which "prints" to a file of zipped xmls.

Will this feature affect UI controls?

no

weltkante avatar Jul 07 '20 13:07 weltkante