-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSplitContainerUtilities.cs
More file actions
78 lines (45 loc) · 2.15 KB
/
SplitContainerUtilities.cs
File metadata and controls
78 lines (45 loc) · 2.15 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
using System.Windows.Forms;
namespace Gsemac.Forms {
public static class SplitContainerUtilities {
// Public members
public static void SetSmoothResizingEnabled(SplitContainer splitContainer, bool value) {
if (value) {
splitContainer.MouseDown += SmoothResizingMouseDownEventHandler;
splitContainer.MouseUp += SmoothResizingMouseUpEventHandler;
splitContainer.MouseMove += SmoothResizingMouseMoveEventHandler;
}
else {
splitContainer.MouseDown -= SmoothResizingMouseDownEventHandler;
splitContainer.MouseUp -= SmoothResizingMouseUpEventHandler;
splitContainer.MouseMove -= SmoothResizingMouseMoveEventHandler;
}
}
// Private members
private static void SmoothResizingMouseDownEventHandler(object sender, MouseEventArgs e) {
// Temporarily disable normal resizing behavior.
if (sender is SplitContainer splitContainer)
splitContainer.IsSplitterFixed = true;
}
private static void SmoothResizingMouseUpEventHandler(object sender, MouseEventArgs e) {
// Restore normal resizing behavior.
if (sender is SplitContainer splitContainer)
splitContainer.IsSplitterFixed = false;
}
private static void SmoothResizingMouseMoveEventHandler(object sender, MouseEventArgs e) {
if (sender is SplitContainer splitContainer && splitContainer.IsSplitterFixed) {
if (e.Button == MouseButtons.Left) {
if (splitContainer.Orientation == Orientation.Vertical && e.X > 0 && e.X < splitContainer.Width) {
splitContainer.SplitterDistance = e.X;
}
else if (e.Y > 0 && e.Y < splitContainer.Height) {
splitContainer.SplitterDistance = e.Y;
}
splitContainer.Refresh();
}
else {
splitContainer.IsSplitterFixed = false;
}
}
}
}
}