-
Notifications
You must be signed in to change notification settings - Fork 27
/
SeekBar.cs
47 lines (43 loc) · 1.43 KB
/
SeekBar.cs
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.Windows.Forms;
namespace Bonsai.Design
{
/// <summary>
/// Represents a horizontal seek bar.
/// </summary>
public class SeekBar : HScrollBar
{
const int WM_LBUTTONDOWN = 0x201;
const int WM_LBUTTONUP = 0x202;
/// <inheritdoc/>
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_LBUTTONDOWN:
var lParam = m.LParam.ToInt64();
var x = (int)(lParam & ushort.MaxValue);
if (x >= SystemInformation.HorizontalScrollBarArrowWidth && x < Width - SystemInformation.HorizontalScrollBarArrowWidth)
{
x -= SystemInformation.HorizontalScrollBarArrowWidth;
var barWidth = Width - 2 * SystemInformation.HorizontalScrollBarArrowWidth;
Value = (int)(((float)x / barWidth) * (Maximum - Minimum));
}
base.WndProc(ref m);
break;
default:
base.WndProc(ref m);
break;
}
}
/// <inheritdoc/>
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
}
/// <inheritdoc/>
protected override void OnScroll(ScrollEventArgs se)
{
base.OnScroll(se);
}
}
}