-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix issue 14859: CheckBox and RadioButton ignore explicit BackColor values in VisualStylesMode.Net11 #14865
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
base: main
Are you sure you want to change the base?
Fix issue 14859: CheckBox and RadioButton ignore explicit BackColor values in VisualStylesMode.Net11 #14865
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -571,7 +571,7 @@ public void CheckBox_AppearanceChanged_RecreatesModernAdapter() | |
| [InlineData(CheckState.Unchecked, false)] | ||
| [InlineData(CheckState.Checked, true)] | ||
| [InlineData(CheckState.Indeterminate, true)] | ||
| public void CheckBox_ModernGlyph_RendersAccentForCheckedStates(CheckState checkState, bool expectedAccent) | ||
| public void CheckBox_ModernGlyph_UsesExplicitBackColorWithoutTintingCheckedGlyph(CheckState checkState, bool expectedAccent) | ||
| { | ||
| if (SystemInformation.HighContrast) | ||
| { | ||
|
|
@@ -582,6 +582,7 @@ public void CheckBox_ModernGlyph_RendersAccentForCheckedStates(CheckState checkS | |
| using CheckBox box = new() | ||
| { | ||
| BackColor = Color.Red, | ||
| UseVisualStyleBackColor = true, | ||
| CheckState = checkState, | ||
| Size = new Size(40, 24), | ||
| VisualStylesMode = VisualStylesMode.Net11 | ||
|
|
@@ -594,7 +595,36 @@ public void CheckBox_ModernGlyph_RendersAccentForCheckedStates(CheckState checkS | |
|
|
||
| box.CreateStandardAdapter().PaintUp(e, checkState); | ||
|
|
||
| Assert.Equal(expectedAccent, CountPixels(bitmap, Color.Red) > 0); | ||
| Color backgroundPixel = bitmap.GetPixel(box.Width - 2, box.Height / 2); | ||
| Assert.Equal(Color.Red.ToArgb(), backgroundPixel.ToArgb()); | ||
| Assert.Equal( | ||
| expectedAccent, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assertion is environment-dependent because the entire control background is |
||
| CountPixels(bitmap, Application.SystemVisualSettings.AccentColor) > 0); | ||
| } | ||
|
|
||
| [WinFormsFact] | ||
| public void CheckBox_ModernGlyph_UsesExplicitBackColorWhenVisualStyleBackgroundDisabled() | ||
| { | ||
| using Panel parent = new() { BackColor = Color.White }; | ||
| using CheckBox box = new() | ||
| { | ||
| BackColor = Color.Aqua, | ||
| CheckState = CheckState.Unchecked, | ||
| Text = string.Empty, | ||
| Size = new Size(40, 24), | ||
| VisualStylesMode = VisualStylesMode.Net11 | ||
| }; | ||
|
|
||
| parent.Controls.Add(box); | ||
|
|
||
| using Bitmap bitmap = new(box.Width, box.Height); | ||
| using Graphics graphics = Graphics.FromImage(bitmap); | ||
| PaintEventArgs e = new(graphics, box.ClientRectangle); | ||
|
|
||
| box.CreateStandardAdapter().PaintUp(e, box.CheckState); | ||
|
|
||
| Color backgroundPixel = bitmap.GetPixel(box.Width - 2, box.Height / 2); | ||
| Assert.Equal(Color.Aqua.ToArgb(), backgroundPixel.ToArgb()); | ||
| } | ||
|
|
||
| [WinFormsFact] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explicit translucent
BackColorvalues are still ignored here.ButtonBasesupports transparent back colors, but whenHasTransparency()is true this falls through toParentBackgroundRenderer.Paint. With a parent, that helper paints only the parent background;Control.BackColoris merely a no-parent fallback and is never composited over it. For example, a 50%-alpha AquaBackColoron a white parent still renders white. Please paint the parent first and then overlay the translucent control color. The same issue exists inRadioButtonModernAdapter.