-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVariableNumericUpDown.cs
86 lines (69 loc) · 2.48 KB
/
VariableNumericUpDown.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
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
81
82
83
84
85
86
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TriDelta.DrawTextMode {
public class VariableNumericUpDown : NumericUpDown {
decimal incshift = 0;
decimal incctrl = 0;
decimal incalt = 0;
[Category("Data")]
[Description("Increment to use when the Shift button is held")]
public decimal IncrementShift {
get { return incshift; }
set { incshift = value; }
}
[Category("Data")]
[Description("Increment to use when the Control button is held")]
public decimal IncrementCtrl {
get { return incctrl; }
set { incctrl = value; }
}
[Category("Data")]
[Description("Increment to use when the Alt button is held")]
public decimal IncrementAlt {
get { return incalt; }
set { incalt = value; }
}
public override void UpButton() {
decimal oldinc = this.Increment;
if ((ModifierKeys & Keys.Shift) > 0)
Increment = IncrementShift;
else if ((ModifierKeys & Keys.Control) > 0)
Increment = IncrementCtrl;
else if ((ModifierKeys & Keys.Alt) > 0)
Increment = IncrementAlt;
if (Increment == 0)
Increment = oldinc;
base.UpButton();
this.Increment = oldinc;
}
public override void DownButton() {
decimal oldinc = this.Increment;
if ((ModifierKeys & Keys.Shift) > 0)
Increment = IncrementShift;
else if ((ModifierKeys & Keys.Control) > 0)
Increment = IncrementCtrl;
else if ((ModifierKeys & Keys.Alt) > 0)
Increment = IncrementAlt;
if (Increment == 0)
Increment = oldinc;
base.DownButton();
this.Increment = oldinc;
}
protected override void OnMouseWheel(MouseEventArgs e) {
int notches = Math.Abs(e.Delta) / SystemInformation.MouseWheelScrollDelta;
if (e.Delta > 0) {
for (var i = 0; i < notches; i++)
this.UpButton();
} else {
for (var i = 0; i < notches; i++)
this.DownButton();
}
((HandledMouseEventArgs)e).Handled = true;
}
}
}