From 672a2acba6c04532f34fd5177f9f8450089805d0 Mon Sep 17 00:00:00 2001 From: Miepee Date: Sat, 3 Sep 2022 16:54:41 +0200 Subject: [PATCH] Make our custom buttons usable with Tab --- .../MainForm/CustomControls/CustomButton.cs | 40 +++++++++++++------ .../MainForm/CustomControls/ImageButton.cs | 3 ++ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/AM2RLauncher/AM2RLauncher/MainForm/CustomControls/CustomButton.cs b/AM2RLauncher/AM2RLauncher/MainForm/CustomControls/CustomButton.cs index bf318a4..fe9b1de 100644 --- a/AM2RLauncher/AM2RLauncher/MainForm/CustomControls/CustomButton.cs +++ b/AM2RLauncher/AM2RLauncher/MainForm/CustomControls/CustomButton.cs @@ -32,12 +32,11 @@ public class CustomButton : Drawable get { return base.Enabled; } set { - if (base.Enabled != value) - { - base.Enabled = value; - if (Loaded) - Invalidate(); - } + if (base.Enabled == value) + return; + base.Enabled = value; + if (Loaded) + Invalidate(); } } @@ -88,7 +87,11 @@ public class CustomButton : Drawable } /// Default constructor. Sets to true. - public CustomButton() { Enabled = true; } + public CustomButton() + { + Enabled = true; + CanFocus = true; + } /// Event raised when this control is resized. /// @@ -106,11 +109,10 @@ public class CustomButton : Drawable protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); - if (Enabled) - { - mouseDown = true; - Invalidate(); - } + if (!Enabled) + return; + mouseDown = true; + Invalidate(); } /// @@ -137,6 +139,20 @@ public class CustomButton : Drawable Invalidate(); } + protected override void OnGotFocus(EventArgs e) + { + hover = true; + base.OnGotFocus(e); + Invalidate(); + } + + protected override void OnLostFocus(EventArgs e) + { + hover = false; + base.OnLostFocus(e); + Invalidate(); + } + /// /// Event raised when the mouse is released over this control's bounding box. /// diff --git a/AM2RLauncher/AM2RLauncher/MainForm/CustomControls/ImageButton.cs b/AM2RLauncher/AM2RLauncher/MainForm/CustomControls/ImageButton.cs index 5b85cbd..f22f45e 100644 --- a/AM2RLauncher/AM2RLauncher/MainForm/CustomControls/ImageButton.cs +++ b/AM2RLauncher/AM2RLauncher/MainForm/CustomControls/ImageButton.cs @@ -99,5 +99,8 @@ public class ImageButton : CustomButton var xoffset = (this.Size.Width - size.Width) / 2; var yoffset = (this.Size.Height - size.Height) / 2; pe.Graphics.DrawImage(image, xoffset, yoffset, size.Width, size.Height); + if (Hover) + // This can probably be done prettier, but can't be bothered to much with it to be honest. + pe.Graphics.DrawRectangle(SystemColors.Highlight, xoffset, yoffset, size.Width, size.Height); } } \ No newline at end of file