@@ -70,13 +70,13 @@ public void PrintPreviewControl_ForeColorReset_ShouldSerializeReturnsFalse()
7070 }
7171
7272 [ WinFormsFact ]
73- public void PrintPreviewControl_PageWithNoImage_RendersWhiteNotForeColor ( )
73+ public void PrintPreviewControl_PageWithNoImage_DefaultForeColor_RendersWhite ( )
7474 {
7575 // Regression test for #14838: a page with no drawable content (e.g. from an empty
76- // PrintDocument) must render as white paper, not as a solid ForeColor rectangle.
76+ // PrintDocument), with ForeColor left at its default, must render as white paper,
77+ // not as a solid black rectangle.
7778 using PrintPreviewControl control = new ( )
7879 {
79- ForeColor = Color . Black ,
8080 Size = new Size ( 200 , 200 )
8181 } ;
8282
@@ -95,6 +95,31 @@ public void PrintPreviewControl_PageWithNoImage_RendersWhiteNotForeColor()
9595 Assert . Equal ( Color . White . ToArgb ( ) , centerPixel . ToArgb ( ) ) ;
9696 }
9797
98+ [ WinFormsFact ]
99+ public void PrintPreviewControl_PageWithNoImage_ExplicitForeColor_RendersForeColor ( )
100+ {
101+ // ForeColor has driven the page background fill since the original .NET Framework port;
102+ // an explicitly set value must still be honored (see PR #14857 discussion), not overridden
103+ // by the white default that only applies when ForeColor was never set.
104+ using PrintPreviewControl control = new ( )
105+ {
106+ ForeColor = Color . Red ,
107+ Size = new Size ( 200 , 200 )
108+ } ;
109+
110+ control . CreateControl ( ) ;
111+
112+ PreviewPageInfo [ ] pageInfo = [ new ( image : null , physicalSize : new Size ( 850 , 1100 ) ) ] ;
113+ control . TestAccessor . Dynamic . _pageInfo = pageInfo ;
114+
115+ using Bitmap bitmap = new ( control . Width , control . Height ) ;
116+ control . DrawToBitmap ( bitmap , new Rectangle ( Point . Empty , control . Size ) ) ;
117+
118+ Color centerPixel = bitmap . GetPixel ( bitmap . Width / 2 , bitmap . Height / 2 ) ;
119+
120+ Assert . Equal ( Color . Red . ToArgb ( ) , centerPixel . ToArgb ( ) ) ;
121+ }
122+
98123 [ Fact ]
99124 public void ShowPrintPreviewControlHighContrast_BackColorIsCorrect ( )
100125 {
0 commit comments