-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClipHistoryCustomizer.cs
More file actions
80 lines (66 loc) · 2.25 KB
/
ClipHistoryCustomizer.cs
File metadata and controls
80 lines (66 loc) · 2.25 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Drawing;
using System.Windows.Forms;
public class ClipHistoryCustomizer
{
private ListBox _clipHistory;
private Panel _borderPanel;
private int _hoveredIndex = -1;
public ClipHistoryCustomizer(ListBox clipHistory, Form parentForm)
{
_clipHistory = clipHistory;
// Set ListBox to OwnerDraw mode
_clipHistory.DrawMode = DrawMode.OwnerDrawFixed;
// Attach the events
_clipHistory.DrawItem += ClipHistory_DrawItem;
_clipHistory.MouseMove += ClipHistory_MouseMove;
_clipHistory.MouseLeave += ClipHistory_MouseLeave;
// Add a bottom border using a Panel
_borderPanel = new Panel
{
Dock = DockStyle.Bottom,
Height = 2,
BackColor = Color.Gray
};
parentForm.Controls.Add(_borderPanel);
_borderPanel.BringToFront();
}
// Handle the DrawItem event for custom rendering
private void ClipHistory_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
bool isHovered = e.Index == _hoveredIndex;
Color textColor = isHovered ? Color.White : Color.White;
Color backgroundColor = isHovered ? Color.DimGray : _clipHistory.BackColor;
using (Brush backgroundBrush = new SolidBrush(backgroundColor))
using (Brush textBrush = new SolidBrush(textColor))
{
e.Graphics.FillRectangle(backgroundBrush, e.Bounds);
if (e.Index >= 0)
{
e.Graphics.DrawString(
_clipHistory.Items[e.Index].ToString(),
e.Font,
textBrush,
e.Bounds);
}
}
e.DrawFocusRectangle();
}
// Handle the MouseMove event for hover effect
private void ClipHistory_MouseMove(object sender, MouseEventArgs e)
{
int index = _clipHistory.IndexFromPoint(e.Location);
if (index != _hoveredIndex)
{
_hoveredIndex = index;
_clipHistory.Invalidate();
}
}
// Handle the MouseLeave event to reset hover effect
private void ClipHistory_MouseLeave(object sender, EventArgs e)
{
_hoveredIndex = -1;
_clipHistory.Invalidate();
}
}