Skip to content
Open
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 @@ -49,6 +49,7 @@ public partial class PrintPreviewControl : Control
private double _zoom = DefaultZoom;
private bool _pageInfoCalcPending;
private bool _exceptionPrinting;
private bool _isForeColorSet;

/// <summary>
/// Initializes a new instance of the <see cref="PrintPreviewControl"/> class.
Expand All @@ -57,6 +58,7 @@ public PrintPreviewControl()
{
ResetBackColor();
ResetForeColor();
ForeColorChanged += (_, _) => _isForeColorSet = true;
Size = new Size(100, 100);
SetStyle(ControlStyles.ResizeRedraw, false);
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
Expand Down Expand Up @@ -295,9 +297,13 @@ public override string Text
internal override bool ShouldSerializeBackColor() => !BackColor.Equals(SystemColors.AppWorkspace);

[EditorBrowsable(EditorBrowsableState.Never)]
public override void ResetForeColor() => ForeColor = Color.White;
public override void ResetForeColor()
{
ForeColor = SystemColors.ControlText;
_isForeColorSet = false;
}

internal override bool ShouldSerializeForeColor() => !ForeColor.Equals(Color.White);
internal override bool ShouldSerializeForeColor() => _isForeColorSet;

internal override bool SupportsUiaProviders => true;

Expand Down Expand Up @@ -592,7 +598,7 @@ private void CalculatePageInfo()

private void DrawMessage(Graphics g, Rectangle rect, bool isExceptionPrinting)
{
Color brushColor = ShouldSerializeForeColor() ? ForeColor : SystemColors.ControlText;
Color brushColor = _isForeColorSet ? ForeColor : SystemColors.ControlText;
if (SystemInformation.HighContrast && Parent is Control parent)
{
brushColor = parent.BackColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,50 @@ public void ShowPrintPreviewControl_BackColorIsCorrect()
Assert.Equal(Color.Green.ToArgb(), actualBackColorArgb);
}

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

Assert.Equal(SystemColors.ControlText.ToArgb(), control.ForeColor.ToArgb());
}

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

// ForeColor not explicitly set: ShouldSerializeForeColor must return false.
Assert.False(control.TestAccessor.Dynamic.ShouldSerializeForeColor());
}

[Fact]
public void PrintPreviewControl_ForeColorWhiteExplicitlySet_ShouldSerializeReturnsTrue()
{
// Regression: #14420 - explicitly setting White must be distinguishable from the default.
PrintPreviewControl control = new() { ForeColor = Color.White };

Assert.True(control.TestAccessor.Dynamic.ShouldSerializeForeColor());
}

[Fact]
public void PrintPreviewControl_ForeColorNonDefault_ShouldSerializeReturnsTrue()
{
PrintPreviewControl control = new() { ForeColor = Color.Red };

Assert.True(control.TestAccessor.Dynamic.ShouldSerializeForeColor());
}

[Fact]
public void PrintPreviewControl_ForeColorReset_ShouldSerializeReturnsFalse()
{
PrintPreviewControl control = new() { ForeColor = Color.Red };
control.ResetForeColor();

Assert.False(control.TestAccessor.Dynamic.ShouldSerializeForeColor());
Assert.Equal(SystemColors.ControlText.ToArgb(), control.ForeColor.ToArgb());
}

[Fact]
public void ShowPrintPreviewControlHighContrast_BackColorIsCorrect()
{
Expand Down