dotnet / dotnet/winforms

Control printing test coverage

Open
#3,540 0 comments 0 reactions 0 assignees View on GitHub
test-enhancement
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

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

During PR review it [was noted](https://github.com/dotnet/winforms/pull/3532#discussion_r449221086) 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.