-
Notifications
You must be signed in to change notification settings - Fork 1
/
SliderPanel.cs
149 lines (141 loc) · 4.94 KB
/
SliderPanel.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
namespace RiverSimulationApplication
{
class SliderPanel
{
private static Timer slideTimer;
private const int slideInterval = 30; //ms
private const int slideDuration = 480; //ms
private static Panel workPanel;
private static Direction showDirection = Direction.ToRight;
private static bool backMode = false;
private static Size parentSize = new Size();
public SliderPanel()
{
// Create a timer with a ten second interval.
slideTimer = new System.Windows.Forms.Timer();
// Hook up the Elapsed event for the timer.
slideTimer.Tick += new EventHandler(OnTimedEvent);
slideTimer.Interval = slideInterval;
}
public enum Direction
{
ToRight,
ToLeft,
ToTop,
ToBottom,
Back
}
public void SlidePanel(Panel p, Direction d, Size ps)
{
if(p != null)
{
workPanel = p;
}
parentSize = ps;
sliderPanelWidth = workPanel.Width;
sliderPanelHeight = workPanel.Height;
if (sliderPanelWidth > 0)
{
switch(d)
{
case Direction.ToRight:
workPanel.Top = 0;
workPanel.Left = 0 - p.Width;
workPanel.Visible = true;
workPanel.BringToFront();
showDirection = d;
break;
case Direction.ToLeft:
workPanel.Top = 0;
workPanel.Left = parentSize.Width;
workPanel.Visible = true;
workPanel.BringToFront();
showDirection = d;
break;
case Direction.Back:
backMode = true;
break;
default:
//To do ...
break;
}
}
slideTimer.Enabled = true;
}
private static int sliderPanelWidth = 0;
private static int sliderPanelHeight = 0;
// Specify what you want to happen when the Elapsed event is
// raised.
private void OnTimedEvent(object sender, EventArgs e)
{
bool finished = false;
if (backMode)
{
switch (showDirection)
{
case Direction.ToRight:
workPanel.Left -= sliderPanelWidth / (slideDuration / slideInterval);
if (workPanel.Left <= 0 - sliderPanelWidth)
{
workPanel.Left = 0 - sliderPanelWidth;
finished = true;
}
break;
case Direction.ToLeft:
workPanel.Left += sliderPanelWidth / (slideDuration / slideInterval);
if (workPanel.Left >= parentSize.Width)
{
workPanel.Left = parentSize.Width;
finished = true;
}
break;
default:
//To do ...
break;
}
}
else
{
switch (showDirection)
{
case Direction.ToRight:
workPanel.Left += sliderPanelWidth / (slideDuration / slideInterval);
if (workPanel.Left >= 0)
{
workPanel.Left = 0;
finished = true;
}
break;
case Direction.ToLeft:
workPanel.Left -= sliderPanelWidth / (slideDuration / slideInterval);
if (workPanel.Left + workPanel.Width <= parentSize.Width)
{
workPanel.Left = parentSize.Width - workPanel.Width;
finished = true;
}
break;
default:
//To do ...
break;
}
}
if(finished)
{
slideTimer.Enabled = false;
if (backMode)
{
workPanel.Visible = false;
backMode = false;
}
}
//Console.WriteLine("The Elapsed event was raised at {0}", e.SignalTime);
}
}
}