Skip to content

Commit 3a6805c

Browse files
authored
Fix modern RadioButton glyph clipping in RTL layouts (#14904)
## Proposed changes - Added DPI-aware glyph padding in `RadioButtonModernAdapter`, preventing RTL hover clipping - Added regression coverage in `RadioButtonTests` <!-- We are in TELL-MODE the following section must be completed --> ## Customer Impact - RadioButton glyphs now render correctly without clipping when using `RightToLeft.Yes` with .NET 11 visual styles, including during mouse hover. The change also respects DPI scaling.
1 parent 69aa55b commit 3a6805c

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/RadioButtonModernAdapter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ protected override ButtonBaseAdapter CreateButtonAdapter()
6161
protected override LayoutOptions Layout(PaintEventArgs e)
6262
{
6363
LayoutOptions layout = CommonLayout();
64+
layout.CheckPaddingSize = Control.LogicalToDeviceUnits(2);
6465
layout.CheckSize = Math.Max(
6566
Control.LogicalToDeviceUnits(13),
6667
(int)(Control.Font.Height * 0.9f));

src/test/unit/System.Windows.Forms/System/Windows/Forms/RadioButtonTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,35 @@ public void RadioButton_ModernGlyph_RendersAccentWhenChecked(bool isChecked, boo
237237
Assert.Equal(expectedAccent, CountPixels(bitmap, Color.Red) > 0);
238238
}
239239

240+
[WinFormsFact]
241+
public void RadioButton_ModernGlyph_RightToLeftHovered_DoesNotClipAtRightEdge()
242+
{
243+
using Panel parent = new() { BackColor = Color.White };
244+
using RadioButton control = new()
245+
{
246+
BackColor = Color.White,
247+
RightToLeft = RightToLeft.Yes,
248+
Size = new Size(40, 24),
249+
VisualStylesMode = VisualStylesMode.Net11
250+
};
251+
control.FlatAppearance.BorderColor = Color.Black;
252+
parent.Controls.Add(control);
253+
254+
control.TestAccessor.Dynamic.OnMouseEnter(EventArgs.Empty);
255+
control.RadioGlyphRenderer.SetInteractionState(hovered: true, focused: false);
256+
control.RadioGlyphRenderer.EndAnimation();
257+
using Bitmap bitmap = new(control.Width, control.Height);
258+
using Graphics graphics = Graphics.FromImage(bitmap);
259+
PaintEventArgs e = new(graphics, control.ClientRectangle);
260+
261+
control.CreateStandardAdapter().PaintOver(e, CheckState.Unchecked);
262+
263+
for (int y = 0; y < bitmap.Height; y++)
264+
{
265+
Assert.Equal(0, bitmap.GetPixel(bitmap.Width - 1, y).A);
266+
}
267+
}
268+
240269
[WinFormsFact]
241270
public void RadioButton_ModernGlyph_DefaultCheckedColorUsesWindowsAccent()
242271
{

0 commit comments

Comments
 (0)