Skip to content

Commit df56bee

Browse files
authored
Merge pull request #12478 from Epica3055/backportPr-12368and12448
[release/9.0] Informational text in PrintPreviewControl has low contrast in basic and HightContrast themes.
2 parents 633262b + d07dd28 commit df56bee

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

src/System.Windows.Forms/src/System/Windows/Forms/Printing/PrintPreviewControl.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,13 @@ private void CalculatePageInfo()
592592

593593
private void DrawMessage(Graphics g, Rectangle rect, bool isExceptionPrinting)
594594
{
595-
using var brush = ForeColor.GetCachedSolidBrushScope();
595+
Color brushColor = SystemColors.ControlText;
596+
if (SystemInformation.HighContrast && Parent is Control parent)
597+
{
598+
brushColor = parent.BackColor;
599+
}
600+
601+
using var brush = brushColor.GetCachedSolidBrushScope();
596602

597603
using StringFormat format = new()
598604
{
@@ -737,7 +743,7 @@ private void PaintFocus(PaintEventArgs e, bool isHighContrast)
737743
/// </returns>
738744
private Color GetBackColor(bool isHighContract)
739745
{
740-
return (isHighContract && !ShouldSerializeBackColor()) ? SystemColors.ControlDark : BackColor;
746+
return (isHighContract && !ShouldSerializeBackColor()) ? SystemColors.ControlDarkDark : BackColor;
741747
}
742748

743749
private static int PixelsToPhysical(int pixels, int dpi) => (int)(pixels * 100.0 / dpi);

src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Printing/PrintPreviewControlTests.cs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,36 @@ namespace System.Windows.Forms.Tests;
88
// NB: doesn't require thread affinity
99
public class PrintPreviewControlTests
1010
{
11-
private const int EmptyColorArgb = 0;
12-
private const int BlueColorArgb = -16776961;
13-
private const int GreenColorArgb = -16744448;
14-
private const int ControlDarkColorArgb = -6250336;
15-
private const int AppWorkSpaceNoHcColorArgb = -5526613;
16-
private const int AppWorkSpaceHcColorArgb = -1;
17-
18-
[Theory]
19-
[InlineData(EmptyColorArgb, false, AppWorkSpaceNoHcColorArgb)]
20-
[InlineData(EmptyColorArgb, true, ControlDarkColorArgb)]
21-
[InlineData(BlueColorArgb, false, BlueColorArgb)]
22-
[InlineData(GreenColorArgb, true, GreenColorArgb)]
23-
public void ShowPrintPreviewControl_BackColorIsCorrect(int customBackColorArgb, bool isHighContrast, int expectedBackColorArgb)
11+
[Fact]
12+
public void ShowPrintPreviewControl_BackColorIsCorrect()
2413
{
2514
PrintPreviewControl control = new();
2615

27-
if (customBackColorArgb != EmptyColorArgb)
28-
{
29-
control.BackColor = Color.FromArgb(customBackColorArgb);
30-
}
16+
int actualBackColorArgb = control.TestAccessor().Dynamic.GetBackColor(false).ToArgb();
17+
Assert.Equal(SystemColors.AppWorkspace.ToArgb(), actualBackColorArgb);
3118

32-
int actualBackColorArgb = control.TestAccessor().Dynamic.GetBackColor(isHighContrast).ToArgb();
33-
Assert.Equal(expectedBackColorArgb, actualBackColorArgb);
19+
control.BackColor = Color.Green;
3420

21+
actualBackColorArgb = control.TestAccessor().Dynamic.GetBackColor(false).ToArgb();
22+
Assert.Equal(Color.Green.ToArgb(), actualBackColorArgb);
23+
}
24+
25+
[Fact]
26+
public void ShowPrintPreviewControlHighContrast_BackColorIsCorrect()
27+
{
28+
PrintPreviewControl control = new();
29+
30+
int actualBackColorArgb = control.TestAccessor().Dynamic.GetBackColor(true).ToArgb();
31+
32+
Assert.Equal(SystemColors.ControlDarkDark.ToArgb(), actualBackColorArgb);
3533
// Default AppWorkSpace color in HC theme does not allow to follow HC standards.
36-
if (isHighContrast)
37-
{
38-
Assert.True(!AppWorkSpaceHcColorArgb.Equals(actualBackColorArgb));
39-
}
34+
Assert.False(SystemColors.AppWorkspace.ToArgb().Equals(actualBackColorArgb));
35+
36+
control.BackColor = Color.Green;
37+
38+
actualBackColorArgb = control.TestAccessor().Dynamic.GetBackColor(true).ToArgb();
39+
40+
Assert.Equal(Color.Green.ToArgb(), actualBackColorArgb);
41+
Assert.False(SystemColors.AppWorkspace.ToArgb().Equals(actualBackColorArgb));
4042
}
4143
}

0 commit comments

Comments
 (0)