-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoFocusButton.cs
More file actions
47 lines (40 loc) · 1.37 KB
/
NoFocusButton.cs
File metadata and controls
47 lines (40 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Drawing;
using System.Windows.Forms;
namespace AudioConverter
{
public class NoFocusButton : Button
{
private bool _isHovered = false; // Track hover state
protected override bool ShowFocusCues
{
get
{
return false;
}
}
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
_isHovered = true;
this.Invalidate(); // Request repaint
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
_isHovered = false;
this.Invalidate(); // Request repaint
}
protected override void OnPaint(PaintEventArgs pevent)
{
base.OnPaint(pevent);
// Draw the background image if available
if (this.BackgroundImage != null)
{
pevent.Graphics.DrawImage(this.BackgroundImage, this.ClientRectangle);
}
// Draw the text in gold if hovered, otherwise white
Color textColor = _isHovered ? System.Drawing.ColorTranslator.FromHtml("#FFD700") : Color.White;
TextRenderer.DrawText(pevent.Graphics, this.Text, this.Font, this.ClientRectangle, textColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
}
}
}