PKHeX/PKHeX.WinForms/Controls/PKM Editor/SelectablePictureBox.cs
2023-03-31 13:00:34 -07:00

43 lines
1.3 KiB
C#

using System;
using System.Windows.Forms;
using System.Windows.Forms.Automation;
namespace PKHeX.WinForms.Controls;
/// <summary>
/// PictureBox control that can be focused and selected.
/// </summary>
/// <remarks>Draws a focus rectangle, and can be tabbed between, raising events for screen readers.</remarks>
public class SelectablePictureBox : PictureBox
{
public SelectablePictureBox() => SetStyle(ControlStyles.Selectable, TabStop = true);
public static int FocusBorderDeflate { get; set; }
protected override void OnMouseDown(MouseEventArgs e)
{
Focus();
base.OnMouseDown(e);
}
protected override void OnEnter(EventArgs e)
{
Invalidate();
base.OnEnter(e);
AccessibilityObject.RaiseAutomationNotification(AutomationNotificationKind.Other,
AutomationNotificationProcessing.All, AccessibleDescription ?? AccessibleName ?? "");
}
protected override void OnLeave(EventArgs e)
{
Invalidate();
base.OnLeave(e);
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
if (!Focused)
return;
var rc = ClientRectangle;
rc.Inflate(-FocusBorderDeflate, -FocusBorderDeflate);
ControlPaint.DrawFocusRectangle(pe.Graphics, rc);
}
}