Skip to content
Open
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 @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace System.Drawing.Design;

Expand All @@ -16,6 +17,45 @@ public SelectionPanelRadioButton()

protected override bool ShowFocusCues => true;

protected override void WndProc(ref Message m)
{
base.WndProc(ref m);

if (m.MsgInternal != PInvokeCore.WM_PAINT || !Focused || !Application.IsDarkModeEnabled)
{
return;
}

using Graphics g = CreateGraphics();
Rectangle focusBounds = GetFocusBounds(g);
if (focusBounds.Width <= 0 || focusBounds.Height <= 0)
{
return;
}

ControlPaint.DrawFocusRectangle(g, focusBounds, ForeColor, BackColor);
Comment thread
SimonZhao888 marked this conversation as resolved.
}

private Rectangle GetFocusBounds(Graphics graphics)
{
if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsSupported)
{
VisualStyleElement element = Checked
? VisualStyleElement.Button.PushButton.Pressed
: VisualStyleElement.Button.PushButton.Normal;

if (VisualStyleRenderer.IsElementDefined(element))
{
VisualStyleRenderer renderer = new(element);
return renderer.GetBackgroundContentRectangle(graphics, ClientRectangle);
}
}

Rectangle focusBounds = ClientRectangle;
focusBounds.Inflate(-SystemInformation.Border3DSize.Width, -SystemInformation.Border3DSize.Height);
return focusBounds;
}

protected override bool IsInputKey(Keys keyData) => keyData switch
{
Keys.Left or Keys.Right or Keys.Up or Keys.Down or Keys.Return => true,
Expand Down