Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/9.0] Informational text in PrintPreviewControl has low contrast in basic and HightContrast themes. #12478

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,13 @@ private void CalculatePageInfo()

private void DrawMessage(Graphics g, Rectangle rect, bool isExceptionPrinting)
{
using var brush = ForeColor.GetCachedSolidBrushScope();
Color brushColor = SystemColors.ControlText;
if (SystemInformation.HighContrast && Parent is Control parent)
{
brushColor = parent.BackColor;
}

ricardobossan marked this conversation as resolved.
Show resolved Hide resolved
using var brush = brushColor.GetCachedSolidBrushScope();

using StringFormat format = new()
{
Expand Down Expand Up @@ -737,7 +743,7 @@ private void PaintFocus(PaintEventArgs e, bool isHighContrast)
/// </returns>
private Color GetBackColor(bool isHighContract)
{
return (isHighContract && !ShouldSerializeBackColor()) ? SystemColors.ControlDark : BackColor;
return (isHighContract && !ShouldSerializeBackColor()) ? SystemColors.ControlDarkDark : BackColor;
}

private static int PixelsToPhysical(int pixels, int dpi) => (int)(pixels * 100.0 / dpi);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,36 @@ namespace System.Windows.Forms.Tests;
// NB: doesn't require thread affinity
public class PrintPreviewControlTests
{
private const int EmptyColorArgb = 0;
private const int BlueColorArgb = -16776961;
private const int GreenColorArgb = -16744448;
private const int ControlDarkColorArgb = -6250336;
private const int AppWorkSpaceNoHcColorArgb = -5526613;
private const int AppWorkSpaceHcColorArgb = -1;

[Theory]
[InlineData(EmptyColorArgb, false, AppWorkSpaceNoHcColorArgb)]
[InlineData(EmptyColorArgb, true, ControlDarkColorArgb)]
[InlineData(BlueColorArgb, false, BlueColorArgb)]
[InlineData(GreenColorArgb, true, GreenColorArgb)]
public void ShowPrintPreviewControl_BackColorIsCorrect(int customBackColorArgb, bool isHighContrast, int expectedBackColorArgb)
[Fact]
public void ShowPrintPreviewControl_BackColorIsCorrect()
{
PrintPreviewControl control = new();

if (customBackColorArgb != EmptyColorArgb)
{
control.BackColor = Color.FromArgb(customBackColorArgb);
}
int actualBackColorArgb = control.TestAccessor().Dynamic.GetBackColor(false).ToArgb();
Assert.Equal(SystemColors.AppWorkspace.ToArgb(), actualBackColorArgb);

int actualBackColorArgb = control.TestAccessor().Dynamic.GetBackColor(isHighContrast).ToArgb();
Assert.Equal(expectedBackColorArgb, actualBackColorArgb);
control.BackColor = Color.Green;

actualBackColorArgb = control.TestAccessor().Dynamic.GetBackColor(false).ToArgb();
Assert.Equal(Color.Green.ToArgb(), actualBackColorArgb);
}

[Fact]
public void ShowPrintPreviewControlHighContrast_BackColorIsCorrect()
{
PrintPreviewControl control = new();

int actualBackColorArgb = control.TestAccessor().Dynamic.GetBackColor(true).ToArgb();

Assert.Equal(SystemColors.ControlDarkDark.ToArgb(), actualBackColorArgb);
// Default AppWorkSpace color in HC theme does not allow to follow HC standards.
if (isHighContrast)
{
Assert.True(!AppWorkSpaceHcColorArgb.Equals(actualBackColorArgb));
}
Assert.False(SystemColors.AppWorkspace.ToArgb().Equals(actualBackColorArgb));

control.BackColor = Color.Green;

actualBackColorArgb = control.TestAccessor().Dynamic.GetBackColor(true).ToArgb();

Assert.Equal(Color.Green.ToArgb(), actualBackColorArgb);
Assert.False(SystemColors.AppWorkspace.ToArgb().Equals(actualBackColorArgb));
}
}
Loading