RibbonPanel.cs
10.7 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Windows.Forms;
namespace RibbonStyle
{
public class RibbonPanel : System.Windows.Forms.Panel
{
public RibbonPanel()
{
this.Padding = new Padding(0, 3, 0, 0);
timer1.Interval = 1;
timer1.Tick += new EventHandler(timer1_Tick);
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
int X0;
int XF;
int Y0;
int YF;
int T = 3;
int i_Zero = 180;
int i_Sweep = 90;
int X; int Y;
GraphicsPath path;
int D = -1;
int R0 = 215;
int G0 = 227;
int B0 = 242;
Color _BaseColor = Color.FromArgb(215, 227, 242);
Color _BaseColorOn = Color.FromArgb(215, 227, 242);
int i_mode = 0; //0 Entering, 1 Leaving
int i_factor = 8;
int i_fR = 1; int i_fG = 1; int i_fB = 1;
int i_Op = 255;
string S_TXT = "";
public Color BaseColor
{
get
{
return _BaseColor;
}
set
{
_BaseColor = value;
R0 = _BaseColor.R;
B0 = _BaseColor.B;
G0 = _BaseColor.G;
}
}
public Color BaseColorOn
{
get
{
return _BaseColorOn;
}
set
{
_BaseColorOn = value;
R0 = _BaseColor.R;
B0 = _BaseColor.B;
G0 = _BaseColor.G;
}
}
public string Caption
{
get
{
return S_TXT;
}
set
{
S_TXT = value;
this.Refresh();
}
}
public int Speed
{
get
{
return i_factor;
}
set
{
i_factor = value;
}
}
public int Opacity
{
get
{
return i_Op;
}
set
{
if (value < 256 | value > -1)
{ i_Op = value; }
}
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
X0 = 0; XF = this.Width + X0 - 3;
Y0 = 0; YF = this.Height + Y0 - 3;
T = 6;
Point P0 = new Point(X0, Y0 - 1);
Point PF = new Point(X0, Y0 + YF + 8);
Pen b1 = new Pen(Color.FromArgb(i_Op, R0 - 18, G0 - 17, B0 - 19));
Pen b2 = Pens.Black;
try
{
//For Light Colors
b2 = new Pen(Color.FromArgb(i_Op, R0 - 74, G0 - 49, B0 - 15));
}
catch
{
//For Dark Colors
b2 = new Pen(Color.FromArgb(i_Op, R0 - 22, G0 - 11, B0));
}
Pen b22 = new Pen(Color.FromArgb(i_Op, R0 + 23, G0 + 21, B0 + 13));
Pen b3 = new Pen(Color.FromArgb(i_Op, R0 + 14, G0 + 9, B0 + 3));
Pen b4 = new Pen(Color.FromArgb(i_Op, R0 - 8, G0 - 4, B0 - 2));
Pen b5 = new Pen(Color.FromArgb(i_Op, R0+4, G0+3, B0+3));
Pen b6 = new Pen(Color.FromArgb(i_Op, R0 - 16, G0 - 11, B0 - 5));
Pen b8 = new Pen(Color.FromArgb(i_Op, R0 + 12, G0 + 17, B0 + 13));
Pen b7 = new Pen(Color.FromArgb(i_Op, R0 - 22, G0 - 10, B0));
e.Graphics.PageUnit = GraphicsUnit.Pixel;
Brush B4 = b4.Brush;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
X = X0; Y = Y0; i_Zero = 180; D = 0;
DrawArc();
e.Graphics.FillPath(b5.Brush, path);
Rectangle rect = e.ClipRectangle;
//LinearGradientBrush brocha = new LinearGradientBrush(rect, b6.Color, b8.Color,LinearGradientMode.Vertical);
LinearGradientBrush brocha = new LinearGradientBrush(P0, PF, b6.Color, b8.Color);
DrawArc2(17, YF + 7);
e.Graphics.FillPath(brocha, path);
D--;
DrawFHalfArc();
e.Graphics.DrawPath(b2, path);
DrawSHalfArc();
e.Graphics.DrawPath(b22, path);
if (activestate)
{
e.Graphics.DrawLine(b5,new Point(activex0+1,0),new Point(activexf-9,0));
}
base.OnPaint(e);
}
protected override void OnMouseEnter(EventArgs e)
{
Point P_EX = Cursor.Position;
P_EX = this.PointToClient(P_EX);
if (P_EX.X > 0 | P_EX.X < this.Width | P_EX.Y > 0 | P_EX.Y < this.Height)
{
i_mode = 0;
timer1.Start();
}
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
Point P_EX = Cursor.Position;
P_EX = this.PointToClient(P_EX);
if (P_EX.X < 0 | P_EX.X >= this.Width | P_EX.Y < 0 | P_EX.Y >= this.Height)
{
i_mode = 1;
timer1.Start();
}
base.OnMouseLeave(e);
}
public void DrawArc()
{
X = X0 - 2; Y = Y0 - 1; i_Zero = 180; D++;
path = new GraphicsPath();
path.AddArc(X + D, Y + D, T, T, i_Zero, i_Sweep); i_Zero += 90; X += XF;
path.AddArc(X - D, Y + D, T, T, i_Zero, i_Sweep); i_Zero += 90; Y += YF;
path.AddArc(X - D, Y - D, T, T, i_Zero, i_Sweep); i_Zero += 90; X -= XF;
path.AddArc(X + D, Y - D, T, T, i_Zero, i_Sweep); i_Zero += 90; Y -= YF;
path.AddArc(X + D, Y + D, T, T, i_Zero, i_Sweep);
}
public void DrawFHalfArc()
{
X = X0 - 2; Y = Y0 - 1; i_Zero = 180; D++;
path = new GraphicsPath();
path.AddArc(X + D, Y + D, T, T, i_Zero, i_Sweep); i_Zero += 90; X += XF - 1;
path.AddArc(X - D, Y + D, T, T, i_Zero, i_Sweep); i_Zero += 90; Y += YF;
path.AddArc(X - D, Y - D, T, T, i_Zero, i_Sweep);
}
public void DrawSHalfArc()
{
X = X0 - 3; Y = Y0 - 1; i_Zero = 180; D++;
path = new GraphicsPath();
i_Zero += 90; X += XF;
path.AddArc(X - D, Y + D, T, T, i_Zero, i_Sweep); i_Zero += 90; Y += YF - 1;
path.AddArc(X - D, Y - D, T, T, i_Zero, i_Sweep); i_Zero += 90; X -= XF - 1;
path.AddArc(X + D, Y - D, T, T, i_Zero, i_Sweep); i_Zero += 90; Y -= YF - 1;
path.AddArc(X + D, Y + D, T, T, i_Zero, i_Sweep);
}
protected override void OnResize(EventArgs eventargs)
{
this.Refresh();
base.OnResize(eventargs);
}
public void DrawArc2(int OF_Y, int SW_Y)
{
X = X0 - 1; Y = Y0 + OF_Y; i_Zero = 180;
path = new GraphicsPath();
path.AddArc(X + D, Y + D, T, T, i_Zero, i_Sweep); i_Zero += 90; X += XF - 1;
path.AddArc(X - D, Y + D, T, T, i_Zero, i_Sweep); i_Zero += 90; Y += SW_Y - 20;
path.AddArc(X - D, Y - D, T, T, i_Zero, i_Sweep); i_Zero += 90; X -= XF - 1;
path.AddArc(X + D, Y - D, T, T, i_Zero, i_Sweep); i_Zero += 90; Y -= SW_Y - 20;
path.AddArc(X + D, Y + D, T, T, i_Zero, i_Sweep);
}
private Timer timer1 = new Timer();
void timer1_Tick(object sender, EventArgs e)
{
#region Entering
if (i_mode == 0)
{
if (System.Math.Abs(_BaseColorOn.R - R0) > i_factor)
{ i_fR = i_factor; }
else { i_fR = 1; }
if (System.Math.Abs(_BaseColorOn.G - G0) > i_factor)
{ i_fG = i_factor; }
else { i_fG = 1; }
if (System.Math.Abs(_BaseColorOn.B - B0) > i_factor)
{ i_fB = i_factor; }
else { i_fB = 1; }
if (_BaseColorOn.R < R0)
{
R0 -= i_fR;
}
else if (_BaseColorOn.R > R0)
{
R0 += i_fR;
}
if (_BaseColorOn.G < G0)
{
G0 -= i_fG;
}
else if (_BaseColorOn.G > G0)
{
G0 += i_fG;
}
if (_BaseColorOn.B < B0)
{
B0 -= i_fB;
}
else if (_BaseColorOn.B > B0)
{
B0 += i_fB;
}
if (_BaseColorOn == Color.FromArgb(R0, G0, B0))
{
timer1.Stop();
}
else
{
this.Refresh();
}
}
#endregion
#region Leaving
if (i_mode == 1)
{
if (System.Math.Abs(_BaseColor.R - R0) < i_factor)
{ i_fR = 1; }
else { i_fR = i_factor; }
if (System.Math.Abs(_BaseColor.G - G0) < i_factor)
{ i_fG = 1; }
else { i_fG = i_factor; }
if (System.Math.Abs(_BaseColor.B - B0) < i_factor)
{ i_fB = 1; }
else { i_fB = i_factor; }
if (_BaseColor.R < R0)
{
R0 -= i_fR;
}
else if (_BaseColor.R > R0)
{
R0 += i_fR;
}
if (_BaseColor.G < G0)
{
G0 -= i_fG;
}
else if (_BaseColor.G > G0)
{
G0 += i_fG;
}
if (_BaseColor.B < B0)
{
B0 -= i_fB;
}
else if (_BaseColor.B > B0)
{
B0 += i_fB;
}
if (_BaseColor == Color.FromArgb(R0, G0, B0))
{
timer1.Stop();
}
else
{
this.Refresh();
}
}
#endregion
}
private int activex0 = 0;
private int activexf = 0;
private bool activestate = false;
public void LinePos(int x0,int xf,bool state)
{
activex0 = x0; activexf = xf; activestate = state;
this.Refresh();
}
}
}