View difference between Paste ID: X3igzHYD and Xh0pFt3G
SHOW: | | - or go back to the newest paste.
1
using Microsoft.VisualBasic;
2
using System;
3
using System.Collections;
4
using System.Collections.Generic;
5
using System.Data;
6
using System.Diagnostics;
7
using System.Drawing;
8
using System.Drawing.Drawing2D;
9
using System.ComponentModel;
10
using System.Windows.Forms;
11
using System.IO;
12
using System.Runtime.InteropServices;
13
using System.Drawing.Imaging;
14
15
16
///''''''''''''''''''''''''''''''''''''''''''''''''
17
///'Credits: Aeonhack, Mavamaarten,  Supportâ„¢.'''''
18
///'''''''''Themebase version: 1.5.4'''''''''''''''
19
///''''''''''''''''''''''''''''''''''''''''''''''''
20
#region "VTheme"
21
22
23
class VTheme : ThemeContainer154
24
{
25
26
    public VTheme()
27
    {
28
        TransparencyKey = Color.Fuchsia;
29
    }
30
31
32
    protected override void ColorHook()
33
    {
34
    }
35
36
    protected override void PaintHook()
37
    {
38
        G.Clear(Color.FromArgb(12, 12, 12));
39
        Pen P = new Pen(Color.FromArgb(32, 32, 32));
40
        G.DrawLine(P, 11, 31, Width - 12, 31);
41
        G.DrawLine(P, 11, 8, Width - 12, 8);
42
        G.FillRectangle(new LinearGradientBrush(new Rectangle(8, 38, Width - 16, Height - 46), Color.FromArgb(12, 12, 12), Color.FromArgb(18, 18, 18), LinearGradientMode.BackwardDiagonal), 8, 38, Width - 16, Height - 46);
43
        DrawText(Brushes.White, HorizontalAlignment.Left, 25, 6);
44
        DrawBorders(new Pen(Color.FromArgb(60, 60, 60)), 1);
45
        DrawBorders(Pens.Black);
46
47
        P = new Pen(Color.FromArgb(25, 25, 25));
48
        G.DrawLine(Pens.Black, 6, 0, 6, Height - 6);
49
        G.DrawLine(Pens.Black, Width - 6, 0, Width - 6, Height - 6);
50
        G.DrawLine(P, 6, 0, 6, Height - 6);
51
        G.DrawLine(P, Width - 8, 0, Width - 8, Height - 6);
52
53
        G.DrawRectangle(Pens.Black, 11, 4, Width - 23, 22);
54
        G.DrawLine(P, 6, Height - 6, Width - 8, Height - 6);
55
        G.DrawLine(Pens.Black, 6, Height - 8, Width - 8, Height - 8);
56
        DrawCorners(Color.Fuchsia);
57
    }
58
59
}
60
61
class VTabControl : TabControl
62
{
63
    int OldIndex;
64
    private int _Speed = 10;
65
    public int Speed
66
    {
67
        get { return _Speed; }
68
        set
69
        {
70
            if (value > 20 | value < -20)
71
            {
72
               MessageBox.Show("Speed needs to be in between -20 and 20.");
73
            }
74
            else
75
            {
76
                _Speed = value;
77
            }
78
        }
79
    }
80
    private Color LightBlack = Color.FromArgb(18, 18, 18);
81
    private Color LighterBlack = Color.FromArgb(21, 21, 21);
82
    private LinearGradientBrush DrawGradientBrush;
83
    private LinearGradientBrush DrawGradientBrush2;
84
    private LinearGradientBrush DrawGradientBrushPen;
85
    private LinearGradientBrush DrawGradientBrushTab;
86
    private Color _ControlBColor;
87
    public Color TabTextColor
88
    {
89
        get { return _ControlBColor; }
90
        set
91
        {
92
            _ControlBColor = value;
93
            Invalidate();
94
        }
95
    }
96
97
    public VTabControl()
98
        : base()
99
    {
100
        SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
101
        TabTextColor = Color.White;
102
    }
103
    public void DoAnimationScrollDown(Control Control1, Control Control2)
104
    {
105
        Graphics G = Control1.CreateGraphics();
106
        Bitmap P1 = new Bitmap(Control1.Width, Control1.Height);
107
        Bitmap P2 = new Bitmap(Control2.Width, Control2.Height);
108
        Control1.DrawToBitmap(P1, new Rectangle(0, 0, Control1.Width, Control1.Height));
109
        Control2.DrawToBitmap(P2, new Rectangle(0, 0, Control2.Width, Control2.Height));
110
        foreach (Control c in Control1.Controls)
111
        {
112
            c.Hide();
113
        }
114
        int Slide = Control1.Height - (Control1.Height % _Speed);
115
        int a = 0;
116
        for (a = 0; a <= Slide; a += _Speed)
117
        {
118
            G.DrawImage(P1, new Rectangle(0, a, Control1.Width, Control1.Height));
119
            G.DrawImage(P2, new Rectangle(0, a - Control2.Height, Control2.Width, Control2.Height));
120
        }
121
        a = Control1.Width;
122
        G.DrawImage(P1, new Rectangle(0, a, Control1.Width, Control1.Height));
123
        G.DrawImage(P2, new Rectangle(0, a - Control2.Height, Control2.Width, Control2.Height));
124
        foreach (Control c in Control2.Controls)
125
        {
126
            c.Show();
127
        }
128
        foreach (Control c in Control1.Controls)
129
        {
130
            c.Show();
131
        }
132
    }
133
    protected override void OnPaint(PaintEventArgs e)
134
    {
135
        base.OnPaint(e);
136
        Rectangle r2 = new Rectangle(2, 0, Width, 25);
137
        Rectangle r3 = new Rectangle(2, 0, Width, 25);
138
        e.Graphics.Clear(Color.FromArgb(18, 18, 18));
139
        Rectangle ItemBounds = default(Rectangle);
140
        SolidBrush TextBrush = new SolidBrush(Color.Empty);
141
        SolidBrush TabBrush = new SolidBrush(Color.FromArgb(15, 15, 15));
142
        DrawGradientBrush2 = new LinearGradientBrush(r3, Color.FromArgb(25, 25, 25), Color.FromArgb(42, 42, 42), LinearGradientMode.ForwardDiagonal);
143
        e.Graphics.FillRectangle(DrawGradientBrush2, r2);
144
        for (int TabItemIndex = 0; TabItemIndex <= this.TabCount - 1; TabItemIndex++)
145
        {
146
            ItemBounds = this.GetTabRect(TabItemIndex);
147
148
            if (Convert.ToBoolean(TabItemIndex & 1))
149
            {
150
                TabBrush.Color = Color.Transparent;
151
            }
152
            else
153
            {
154
                TabBrush.Color = Color.Transparent;
155
            }
156
            e.Graphics.FillRectangle(TabBrush, ItemBounds);
157
            Pen BorderPen = null;
158
            if (TabItemIndex == SelectedIndex)
159
            {
160
                BorderPen = new Pen(Color.Black, 1);
161
            }
162
            else
163
            {
164
                BorderPen = new Pen(Color.Black, 1);
165
            }
166
            Rectangle rPen = new Rectangle(ItemBounds.Location.X + 3, ItemBounds.Location.Y + 0, ItemBounds.Width - 4, ItemBounds.Height - 2);
167
            e.Graphics.DrawRectangle(BorderPen, rPen);
168
            DrawGradientBrushPen = new LinearGradientBrush(rPen, Color.FromArgb(5, 5, 5), Color.FromArgb(24, 24, 24), LinearGradientMode.Vertical);
169
            e.Graphics.FillRectangle(DrawGradientBrushPen, rPen);
170
            BorderPen.Dispose();
171
            StringFormat sf = new StringFormat();
172
            sf.LineAlignment = StringAlignment.Center;
173
            sf.Alignment = StringAlignment.Center;
174
175
            if (this.SelectedIndex == TabItemIndex)
176
            {
177
                TextBrush.Color = TabTextColor;
178
            }
179
            else
180
            {
181
                TextBrush.Color = Color.Gray;
182
            }
183
            e.Graphics.DrawString(this.TabPages[TabItemIndex].Text, this.Font, TextBrush,(this.GetTabRect(TabItemIndex)), sf);
184
            try
185
            {
186
                this.TabPages[TabItemIndex].BackColor = Color.FromArgb(15, 15, 15);
187
188
            }
189
            catch
190
            {
191
            }
192
        }
193
        try
194
        {
195
            foreach (TabPage Page in this.TabPages)
196
            {
197
                Page.BorderStyle = BorderStyle.None;
198
            }
199
        }
200
        catch
201
        {
202
        }
203
        e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.FromArgb(255, Color.Black))), 2, 0, Width - 3, Height - 3);
204
        e.Graphics.DrawRectangle(new Pen(new SolidBrush(LighterBlack)), new Rectangle(3, 24, Width - 5, Height - 28));
205
        e.Graphics.DrawLine(new Pen(new SolidBrush(Color.FromArgb(255, Color.Black))), 2, 23, Width - 2, 23);
206
        e.Graphics.DrawLine(new Pen(new SolidBrush(Color.FromArgb(35, 35, 35))), 0, 0, 1, 1);
207
        e.Graphics.DrawLine(new Pen(new SolidBrush(Color.FromArgb(70, 70, 70))), 2, Height - 2, Width + 1, Height - 2);
208
209
    }
210
    protected override void OnSelecting(System.Windows.Forms.TabControlCancelEventArgs e)
211
    {
212
        if (OldIndex < e.TabPageIndex)
213
        {
214
            DoAnimationScrollUp(TabPages[OldIndex], TabPages[e.TabPageIndex]);
215
        }
216
        else
217
        {
218
            DoAnimationScrollDown(TabPages[OldIndex], TabPages[e.TabPageIndex]);
219
        }
220
    }
221
222
    protected override void OnDeselecting(System.Windows.Forms.TabControlCancelEventArgs e)
223
    {
224
        OldIndex = e.TabPageIndex;
225
    }
226
    public void DoAnimationScrollUp(Control Control1, Control Control2)
227
    {
228
        Graphics G = Control1.CreateGraphics();
229
        Bitmap P1 = new Bitmap(Control1.Width, Control1.Height);
230
        Bitmap P2 = new Bitmap(Control2.Width, Control2.Height);
231
        Control1.DrawToBitmap(P1, new Rectangle(0, 0, Control1.Width, Control1.Height));
232
        Control2.DrawToBitmap(P2, new Rectangle(0, 0, Control2.Width, Control2.Height));
233
234
        foreach (Control c in Control1.Controls)
235
        {
236
            c.Hide();
237
        }
238
        int Slide = Control1.Height - (Control1.Height % _Speed);
239
        int a = 0;
240
        for (a = 0; a >= -Slide; a += -_Speed)
241
        {
242
            G.DrawImage(P1, new Rectangle(0, a, Control1.Width, Control1.Height));
243
            G.DrawImage(P2, new Rectangle(0, a + Control2.Height, Control2.Width, Control2.Height));
244
        }
245
        a = Control1.Width;
246
        G.DrawImage(P1, new Rectangle(0, a, Control1.Width, Control1.Height));
247
        G.DrawImage(P2, new Rectangle(0, a + Control2.Height, Control2.Width, Control2.Height));
248
249
        foreach (Control c in Control2.Controls)
250
        {
251
            c.Show();
252
        }
253
254
        foreach (Control c in Control1.Controls)
255
        {
256
            c.Show();
257
        }
258
    }
259
}
260
261
class VGroupBox : ThemeContainer154
262
{
263
264
    public VGroupBox()
265
    {
266
        ControlMode = true;
267
    }
268
269
270
    protected override void ColorHook()
271
    {
272
    }
273
274
    protected override void PaintHook()
275
    {
276
        G.Clear(Color.Transparent);
277
        DrawBorders(new Pen(Color.FromArgb(36, 36, 36)), 1);
278
        DrawBorders(Pens.Black);
279
        G.DrawLine(new Pen(Color.FromArgb(48, 48, 48)), 1, 1, Width - 2, 1);
280
        G.FillRectangle(new LinearGradientBrush(new Rectangle(8, 8, Width - 16, Height - 16), Color.FromArgb(12, 12, 12), Color.FromArgb(18, 18, 18), LinearGradientMode.BackwardDiagonal), 8, 8, Width - 16, Height - 16);
281
        DrawBorders(new Pen(Color.FromArgb(36, 36, 36)), 7);
282
    }
283
}
284
285
class VSeperator : ThemeControl154
286
{
287
288
    private Orientation _Orientation;
289
    public Orientation Orientation
290
    {
291
        get { return _Orientation; }
292
        set
293
        {
294
            _Orientation = value;
295
296
            if (value == System.Windows.Forms.Orientation.Vertical)
297
            {
298
                LockHeight = 0;
299
                LockWidth = 14;
300
            }
301
            else
302
            {
303
                LockHeight = 14;
304
                LockWidth = 0;
305
            }
306
307
            Invalidate();
308
        }
309
    }
310
311
    public VSeperator()
312
    {
313
        Transparent = true;
314
        BackColor = Color.Transparent;
315
316
        LockHeight = 14;
317
    }
318
319
320
    protected override void ColorHook()
321
    {
322
    }
323
324
    protected override void PaintHook()
325
    {
326
        
327
328
    }
329
330
}
331
332
class VCheckBox : ThemeControl154
333
{
334
    private Pen P1;
335
    private Brush B1;
336
    private Brush B2;
337
    private Brush B3;
338
    private bool _Checked = false;
339
    public bool Checked
340
    {
341
        get { return _Checked; }
342
        set
343
        {
344
            _Checked = value;
345
            Invalidate();
346
        }
347
    }
348
    public VCheckBox()
349
    {
350
        Click += changeChecked;
351
        //BackColor = Color.Transparent
352
        Size = new Size(150, 16);
353
    }
354
355
    private void changeChecked(object sender, EventArgs e)
356
    {
357
        
358
    }
359
    public void changeChecked()
360
    {
361
        switch (_Checked)
362
        {
363
            case false:
364
                _Checked = true;
365
                break;
366
            case true:
367
                _Checked = false;
368
                break;
369
        }
370
    }
371
    protected override void ColorHook()
372
    {
373
        P1 = new Pen(Color.FromArgb(0, 0, 0));
374
        B1 = new SolidBrush(Color.FromArgb(15, Color.FromArgb(26, 26, 26)));
375
        B2 = new SolidBrush(Color.White);
376
        B3 = new SolidBrush(Color.FromArgb(0, 0, 0));
377
    }
378
379
    protected override void PaintHook()
380
    {
381
        G.Clear(Color.Transparent);
382
        G.FillRectangle(B3, 0, 0, 45, 15);
383
        G.FillRectangle(new LinearGradientBrush(new Rectangle(45, 0, Width, Height), Color.FromArgb(12, 12, 12), Color.FromArgb(15, 15, 15), LinearGradientMode.BackwardDiagonal), 45, 0, Width, Height);
384
385
        G.DrawRectangle(P1, 0, 0, 45, 15);
386
        if ((_Checked == false))
387
        {
388
            DrawGradient(Color.FromArgb(15, 15, 15), Color.FromArgb(10, 10, 10), 2, 2, 29, 11, 90);
389
            G.DrawString("OFF", Font, Brushes.Gray, 3, 1);
390
            G.FillRectangle(new LinearGradientBrush(new Rectangle(29, -1, 13, 16), Color.FromArgb(35, 35, 35), Color.FromArgb(25, 25, 25), 90), 29, -1, 13, 16);
391
        }
392
        else
393
        {
394
            DrawGradient(Color.FromArgb(10, 10, 10), Color.FromArgb(20, 20, 20), 15, 2, 28, 11, 90);
395
            G.DrawString("ON", Font, Brushes.White, 18, 0);
396
            G.FillRectangle(new LinearGradientBrush(new Rectangle(2, -1, 13, 16), Color.FromArgb(80, 80, 80), Color.FromArgb(60, 60, 60), 90), 2, -1, 13, 16);
397
        }
398
        G.FillRectangle(B1, 2, 2, 41, 11);
399
        DrawText(B2, HorizontalAlignment.Left, 50, 0);
400
    }
401
}
402
403
class VRadiobutton : ThemeControl154
404
{
405
406
    private bool _Checked;
407
    public bool Checked
408
    {
409
        get { return _Checked; }
410
        set
411
        {
412
            _Checked = value;
413
            Invalidate();
414
        }
415
    }
416
417
    protected override void OnClick(System.EventArgs e)
418
    {
419
        
420
        base.OnClick(e);
421
        foreach (Control C in Parent.Controls)
422
        {
423
            
424
            {
425
                VRadiobutton CC = null;
426
                
427
                CC.Checked = true;
428
            }
429
        }
430
        _Checked = true;
431
    }
432
433
434
    protected override void ColorHook()
435
    {
436
    }
437
438
    protected override void OnTextChanged(System.EventArgs e)
439
    {
440
        base.OnTextChanged(e);
441
        int textSize = 0;
442
        this.Width = 25 + textSize;
443
    }
444
445
    protected override void PaintHook()
446
    {
447
        G.Clear(Color.Transparent);
448
        G.SmoothingMode = SmoothingMode.AntiAlias;
449
450
        if (_Checked == false)
451
        {
452
            G.FillEllipse(new SolidBrush(Color.Black), 0, 0, 16, 16);
453
            LinearGradientBrush Gbrush = new LinearGradientBrush(new Rectangle(1, 1, 14, 14), Color.FromArgb(24, 30, 36), Color.FromArgb(25, 25, 25), 90f);
454
            G.FillEllipse(Gbrush, new Rectangle(1, 1, 14, 14));
455
            Gbrush = new LinearGradientBrush(new Rectangle(2, 2, 12, 12), Color.FromArgb(12, 12, 12), Color.FromArgb(25, 25, 25), 90f);
456
            G.FillEllipse(Gbrush, new Rectangle(2, 2, 12, 12));
457
        }
458
        else
459
        {
460
            G.FillEllipse(new SolidBrush(Color.Black), 0, 0, 16, 16);
461
            LinearGradientBrush Gbrush = new LinearGradientBrush(new Rectangle(1, 1, 14, 14), Color.FromArgb(45, 45, 45), Color.FromArgb(10, 10, 10), 90f);
462
            G.FillEllipse(Gbrush, new Rectangle(1, 1, 14, 14));
463
            Gbrush = new LinearGradientBrush(new Rectangle(2, 2, 12, 12), Color.FromArgb(25, 25, 25), Color.FromArgb(20, 20, 20), 90f);
464
            G.FillEllipse(Gbrush, new Rectangle(2, 2, 12, 12));
465
            G.FillEllipse(Brushes.Black, new Rectangle(5, 6, 5, 5));
466
            LinearGradientBrush Gbrush2 = new LinearGradientBrush(new Rectangle(1, 1, 14, 14), Color.FromArgb(130, 130, 130), Color.FromArgb(20, 20, 20), LinearGradientMode.ForwardDiagonal);
467
            G.FillEllipse(Gbrush2, new Rectangle(3, 3, 10, 10));
468
        }
469
        G.FillRectangle(new LinearGradientBrush(new Rectangle(18, -1, Width, Height + 1), Color.FromArgb(12, 12, 12), Color.FromArgb(15, 15, 15), LinearGradientMode.BackwardDiagonal), 18, -1, Width, Height + 1);
470
        G.DrawString(Text, Font, Brushes.White, 22, 2);
471
    }
472
473
    public VRadiobutton()
474
    {
475
        
476
       
477
    }
478
}
479
480
class VButton : ThemeControl154
481
{
482
483
484
    protected override void ColorHook()
485
    {
486
    }
487
488
    protected override void PaintHook()
489
    {
490
        DrawBorders(new Pen(Color.FromArgb(16, 16, 16)), 1);
491
        G.FillRectangle(new SolidBrush(Color.FromArgb(5, 5, 5)), 0, 0, Width, 8);
492
        DrawBorders(Pens.Black, 3);
493
        DrawBorders(new Pen(Color.FromArgb(24, 24, 24)));
494
495
        if (State == MouseState.Over)
496
        {
497
            G.FillRectangle(new SolidBrush(Color.FromArgb(25, 25, 25)), 3, 3, Width - 6, Height - 6);
498
            DrawBorders(new Pen(Color.FromArgb(0, 0, 0)), 2);
499
        }
500
        else if (State == MouseState.Down)
501
        {
502
            G.FillRectangle(new LinearGradientBrush(new Rectangle(3, 3, Width - 6, Height - 6), Color.FromArgb(12, 12, 12), Color.FromArgb(30, 30, 30), LinearGradientMode.BackwardDiagonal), 3, 3, Width - 6, Height - 6);
503
            DrawBorders(new Pen(Color.FromArgb(0, 0, 0)), 2);
504
        }
505
        else
506
        {
507
            G.FillRectangle(new LinearGradientBrush(new Rectangle(3, 3, Width - 6, Height - 6), Color.FromArgb(9, 9, 9), Color.FromArgb(18, 18, 18), LinearGradientMode.Vertical), 3, 3, Width - 6, Height - 6);
508
            DrawBorders(new Pen(Color.FromArgb(32, 32, 32)), 2);
509
        }
510
        if (State == MouseState.Down)
511
        {
512
            DrawText(Brushes.White, HorizontalAlignment.Center, 2, 2);
513
        }
514
        else
515
        {
516
            DrawText(Brushes.White, HorizontalAlignment.Center, 0, 0);
517
        }
518
    }
519
520
}
521
522
class VTextBox : ThemeControl154
523
{
524
    private TextBox withEventsField_Txt = new TextBox();
525
    public TextBox Txt
526
    {
527
        get { return withEventsField_Txt; }
528
        set
529
        {
530
            if (withEventsField_Txt != null)
531
            {
532
                
533
            }
534
            withEventsField_Txt = value;
535
            if (withEventsField_Txt != null)
536
            {
537
               
538
            }
539
        }
540
541
    }
542
    private bool _Mulitline;
543
    public bool Multiline
544
    {
545
        get { return _Mulitline; }
546
        set { _Mulitline = value; }
547
    }
548
    private bool _PassMask;
549
    public bool UsePasswordMask
550
    {
551
        get { return _PassMask; }
552
        set
553
        {
554
            _PassMask = value;
555
            Txt.UseSystemPasswordChar = value;
556
        }
557
    }
558
    private int _maxchars;
559
    public int MaxCharacters
560
    {
561
        get { return _maxchars; }
562
        set
563
        {
564
            _maxchars = value;
565
            Txt.MaxLength = value;
566
        }
567
    }
568
569
570
    public VTextBox()
571
    {
572
        
573
        Txt.TextAlign = HorizontalAlignment.Left;
574
        Txt.BorderStyle = BorderStyle.None;
575
        Txt.Location = new Point(10, 6);
576
        Txt.Font = new Font("Verdana", 8);
577
        Controls.Add(Txt);
578
        Text = "";
579
        Txt.Text = "";
580
        Size = new Size(150, 25);
581
    }
582
583
    protected override void ColorHook()
584
    {
585
        Txt.ForeColor = Color.White;
586
        Txt.BackColor = Color.FromArgb(15, 15, 15);
587
    }
588
589
    protected override void PaintHook()
590
    {
591
        G.Clear(Color.FromArgb(15, 15, 15));
592
        Txt.Size = new Size(Width - 20, Height - 10);
593
        switch (Multiline)
594
        {
595
            case true:
596
                Size = new Size(Width, Height);
597
                break;
598
            case false:
599
                Size = new Size(Width, 25);
600
                break;
601
        }
602
603
        G.FillRectangle(new SolidBrush(Color.FromArgb(15, 15, 15)), new Rectangle(1, 1, Width - 2, Height - 2));
604
        DrawBorders(new Pen(new SolidBrush(Color.FromArgb(32, 32, 32))), 1);
605
        DrawBorders(new Pen(new SolidBrush(Color.Black)));
606
        DrawCorners(Color.FromArgb(15, 15, 15));
607
        DrawCorners(Color.FromArgb(15, 15, 15), new Rectangle(1, 1, Width - 2, Height - 2));
608
    }
609
    public void TextChngTxtBox()
610
    {
611
        Text = Txt.Text;
612
    }
613
    public void TextChng()
614
    {
615
        Txt.Text = Text;
616
    }
617
}
618
619
#endregion
620
#region "Themebase154"
621
622
//------------------
623
//Creator: aeonhack
624
//Site: elitevs.net
625
//Created: 08/02/2011
626
//Changed: 12/06/2011
627
//Version: 1.5.4
628
//------------------
629
abstract class ThemeContainer154 : ContainerControl
630
{
631
632
    #region " Initialization "
633
634
    protected Graphics G;
635
636
    protected Bitmap B;
637
    public ThemeContainer154()
638
    {
639
        SetStyle((ControlStyles)139270, true);
640
641
        _ImageSize = Size.Empty;
642
        Font = new Font("Verdana", 8);
643
644
        MeasureBitmap = new Bitmap(1, 1);
645
        MeasureGraphics = Graphics.FromImage(MeasureBitmap);
646
647
        DrawRadialPath = new GraphicsPath();
648
649
        InvalidateCustimization();
650
    }
651
652
    protected override sealed void OnHandleCreated(EventArgs e)
653
    {
654
        if (DoneCreation)
655
            InitializeMessages();
656
657
        InvalidateCustimization();
658
        ColorHook();
659
660
        if (!(_LockWidth == 0))
661
            Width = _LockWidth;
662
        if (!(_LockHeight == 0))
663
            Height = _LockHeight;
664
        if (!_ControlMode)
665
            base.Dock = DockStyle.Fill;
666
667
        Transparent = _Transparent;
668
        if (_Transparent && _BackColor)
669
            BackColor = Color.Transparent;
670
671
        base.OnHandleCreated(e);
672
    }
673
674
    private bool DoneCreation;
675
    protected override sealed void OnParentChanged(EventArgs e)
676
    {
677
        base.OnParentChanged(e);
678
679
        if (Parent == null)
680
            return;
681
        _IsParentForm = Parent is Form;
682
683
        if (!_ControlMode)
684
        {
685
            InitializeMessages();
686
687
            if (_IsParentForm)
688
            {
689
                ParentForm.FormBorderStyle = _BorderStyle;
690
                ParentForm.TransparencyKey = _TransparencyKey;
691
692
                if (!DesignMode)
693
                {
694
                    ParentForm.Shown += FormShown;
695
                }
696
            }
697
698
            Parent.BackColor = BackColor;
699
        }
700
701
        OnCreation();
702
        DoneCreation = true;
703
        InvalidateTimer();
704
    }
705
706
    #endregion
707
708
    private void DoAnimation(bool i)
709
    {
710
        OnAnimation();
711
        if (i)
712
            Invalidate();
713
    }
714
715
    protected override sealed void OnPaint(PaintEventArgs e)
716
    {
717
        if (Width == 0 || Height == 0)
718
            return;
719
720
        if (_Transparent && _ControlMode)
721
        {
722
            PaintHook();
723
            e.Graphics.DrawImage(B, 0, 0);
724
        }
725
        else
726
        {
727
            G = e.Graphics;
728
            PaintHook();
729
        }
730
    }
731
732
    protected override void OnHandleDestroyed(EventArgs e)
733
    {
734
        ThemeShare.RemoveAnimationCallback(DoAnimation);
735
        base.OnHandleDestroyed(e);
736
    }
737
738
    private bool HasShown;
739
    private void FormShown(object sender, EventArgs e)
740
    {
741
        if (_ControlMode || HasShown)
742
            return;
743
744
        if (_StartPosition == FormStartPosition.CenterParent || _StartPosition == FormStartPosition.CenterScreen)
745
        {
746
            Rectangle SB = Screen.PrimaryScreen.Bounds;
747
            Rectangle CB = ParentForm.Bounds;
748
            ParentForm.Location = new Point(SB.Width / 2 - CB.Width / 2, SB.Height / 2 - CB.Width / 2);
749
        }
750
751
        HasShown = true;
752
    }
753
754
755
    #region " Size Handling "
756
757
    private Rectangle Frame;
758
    protected override sealed void OnSizeChanged(EventArgs e)
759
    {
760
        if (_Movable && !_ControlMode)
761
        {
762
            Frame = new Rectangle(7, 7, Width - 14, _Header - 7);
763
        }
764
765
        InvalidateBitmap();
766
        Invalidate();
767
768
        base.OnSizeChanged(e);
769
    }
770
771
    protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
772
    {
773
        if (!(_LockWidth == 0))
774
            width = _LockWidth;
775
        if (!(_LockHeight == 0))
776
            height = _LockHeight;
777
        base.SetBoundsCore(x, y, width, height, specified);
778
    }
779
780
    #endregion
781
782
    #region " State Handling "
783
784
    protected MouseState State;
785
    private void SetState(MouseState current)
786
    {
787
        State = current;
788
        Invalidate();
789
    }
790
791
    protected override void OnMouseMove(MouseEventArgs e)
792
    {
793
        if (!(_IsParentForm && ParentForm.WindowState == FormWindowState.Maximized))
794
        {
795
            if (_Sizable && !_ControlMode)
796
                InvalidateMouse();
797
        }
798
799
        base.OnMouseMove(e);
800
    }
801
802
    protected override void OnEnabledChanged(EventArgs e)
803
    {
804
        if (Enabled)
805
            SetState(MouseState.None);
806
        else
807
            SetState(MouseState.Block);
808
        base.OnEnabledChanged(e);
809
    }
810
811
    protected override void OnMouseEnter(EventArgs e)
812
    {
813
        SetState(MouseState.Over);
814
        base.OnMouseEnter(e);
815
    }
816
817
    protected override void OnMouseUp(MouseEventArgs e)
818
    {
819
        SetState(MouseState.Over);
820
        base.OnMouseUp(e);
821
    }
822
823
    protected override void OnMouseLeave(EventArgs e)
824
    {
825
        SetState(MouseState.None);
826
827
        if (GetChildAtPoint(PointToClient(MousePosition)) != null)
828
        {
829
            if (_Sizable && !_ControlMode)
830
            {
831
                Cursor = Cursors.Default;
832
                Previous = 0;
833
            }
834
        }
835
836
        base.OnMouseLeave(e);
837
    }
838
839
    protected override void OnMouseDown(MouseEventArgs e)
840
    {
841
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
842
            SetState(MouseState.Down);
843
844
        if (!(_IsParentForm && ParentForm.WindowState == FormWindowState.Maximized || _ControlMode))
845
        {
846
            if (_Movable && Frame.Contains(e.Location))
847
            {
848
                Capture = false;
849
                WM_LMBUTTONDOWN = true;
850
                DefWndProc(ref Messages[0]);
851
            }
852
            else if (_Sizable && !(Previous == 0))
853
            {
854
                Capture = false;
855
                WM_LMBUTTONDOWN = true;
856
                DefWndProc(ref Messages[Previous]);
857
            }
858
        }
859
860
        base.OnMouseDown(e);
861
    }
862
863
    private bool WM_LMBUTTONDOWN;
864
    protected override void WndProc(ref Message m)
865
    {
866
        base.WndProc(ref m);
867
868
        if (WM_LMBUTTONDOWN && m.Msg == 513)
869
        {
870
            WM_LMBUTTONDOWN = false;
871
872
            SetState(MouseState.Over);
873
            if (!_SmartBounds)
874
                return;
875
876
            if (IsParentMdi)
877
            {
878
                CorrectBounds(new Rectangle(Point.Empty, Parent.Parent.Size));
879
            }
880
            else
881
            {
882
                CorrectBounds(Screen.FromControl(Parent).WorkingArea);
883
            }
884
        }
885
    }
886
887
    private Point GetIndexPoint;
888
    private bool B1;
889
    private bool B2;
890
    private bool B3;
891
    private bool B4;
892
    private int GetIndex()
893
    {
894
        GetIndexPoint = PointToClient(MousePosition);
895
        B1 = GetIndexPoint.X < 7;
896
        B2 = GetIndexPoint.X > Width - 7;
897
        B3 = GetIndexPoint.Y < 7;
898
        B4 = GetIndexPoint.Y > Height - 7;
899
900
        if (B1 && B3)
901
            return 4;
902
        if (B1 && B4)
903
            return 7;
904
        if (B2 && B3)
905
            return 5;
906
        if (B2 && B4)
907
            return 8;
908
        if (B1)
909
            return 1;
910
        if (B2)
911
            return 2;
912
        if (B3)
913
            return 3;
914
        if (B4)
915
            return 6;
916
        return 0;
917
    }
918
919
    private int Current;
920
    private int Previous;
921
    private void InvalidateMouse()
922
    {
923
        Current = GetIndex();
924
        if (Current == Previous)
925
            return;
926
927
        Previous = Current;
928
        switch (Previous)
929
        {
930
            case 0:
931
                Cursor = Cursors.Default;
932
                break;
933
            case 1:
934
            case 2:
935
                Cursor = Cursors.SizeWE;
936
                break;
937
            case 3:
938
            case 6:
939
                Cursor = Cursors.SizeNS;
940
                break;
941
            case 4:
942
            case 8:
943
                Cursor = Cursors.SizeNWSE;
944
                break;
945
            case 5:
946
            case 7:
947
                Cursor = Cursors.SizeNESW;
948
                break;
949
        }
950
    }
951
952
    private Message[] Messages = new Message[9];
953
    private void InitializeMessages()
954
    {
955
        Messages[0] = Message.Create(Parent.Handle, 161, new IntPtr(2), IntPtr.Zero);
956
        for (int I = 1; I <= 8; I++)
957
        {
958
            Messages[I] = Message.Create(Parent.Handle, 161, new IntPtr(I + 9), IntPtr.Zero);
959
        }
960
    }
961
962
    private void CorrectBounds(Rectangle bounds)
963
    {
964
        if (Parent.Width > bounds.Width)
965
            Parent.Width = bounds.Width;
966
        if (Parent.Height > bounds.Height)
967
            Parent.Height = bounds.Height;
968
969
        int X = Parent.Location.X;
970
        int Y = Parent.Location.Y;
971
972
        if (X < bounds.X)
973
            X = bounds.X;
974
        if (Y < bounds.Y)
975
            Y = bounds.Y;
976
977
        int Width = bounds.X + bounds.Width;
978
        int Height = bounds.Y + bounds.Height;
979
980
        if (X + Parent.Width > Width)
981
            X = Width - Parent.Width;
982
        if (Y + Parent.Height > Height)
983
            Y = Height - Parent.Height;
984
985
        Parent.Location = new Point(X, Y);
986
    }
987
988
    #endregion
989
990
991
    #region " Base Properties "
992
993
    public override DockStyle Dock
994
    {
995
        get { return base.Dock; }
996
        set
997
        {
998
            if (!_ControlMode)
999
                return;
1000
            base.Dock = value;
1001
        }
1002
    }
1003
1004
    private bool _BackColor;
1005
    [Category("Misc")]
1006
    public override Color BackColor
1007
    {
1008
        get { return base.BackColor; }
1009
        set
1010
        {
1011
            if (value == base.BackColor)
1012
                return;
1013
1014
            if (!IsHandleCreated && _ControlMode && value == Color.Transparent)
1015
            {
1016
                _BackColor = true;
1017
                return;
1018
            }
1019
1020
            base.BackColor = value;
1021
            if (Parent != null)
1022
            {
1023
                if (!_ControlMode)
1024
                    Parent.BackColor = value;
1025
                ColorHook();
1026
            }
1027
        }
1028
    }
1029
1030
    public override Size MinimumSize
1031
    {
1032
        get { return base.MinimumSize; }
1033
        set
1034
        {
1035
            base.MinimumSize = value;
1036
            if (Parent != null)
1037
                Parent.MinimumSize = value;
1038
        }
1039
    }
1040
1041
    public override Size MaximumSize
1042
    {
1043
        get { return base.MaximumSize; }
1044
        set
1045
        {
1046
            base.MaximumSize = value;
1047
            if (Parent != null)
1048
                Parent.MaximumSize = value;
1049
        }
1050
    }
1051
1052
    public override string Text
1053
    {
1054
        get { return base.Text; }
1055
        set
1056
        {
1057
            base.Text = value;
1058
            Invalidate();
1059
        }
1060
    }
1061
1062
    public override Font Font
1063
    {
1064
        get { return base.Font; }
1065
        set
1066
        {
1067
            base.Font = value;
1068
            Invalidate();
1069
        }
1070
    }
1071
1072
    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1073
    public override Color ForeColor
1074
    {
1075
        get { return Color.Empty; }
1076
        set { }
1077
    }
1078
    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1079
    public override Image BackgroundImage
1080
    {
1081
        get { return null; }
1082
        set { }
1083
    }
1084
    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1085
    public override ImageLayout BackgroundImageLayout
1086
    {
1087
        get { return ImageLayout.None; }
1088
        set { }
1089
    }
1090
1091
    #endregion
1092
1093
    #region " Public Properties "
1094
1095
    private bool _SmartBounds = true;
1096
    public bool SmartBounds
1097
    {
1098
        get { return _SmartBounds; }
1099
        set { _SmartBounds = value; }
1100
    }
1101
1102
    private bool _Movable = true;
1103
    public bool Movable
1104
    {
1105
        get { return _Movable; }
1106
        set { _Movable = value; }
1107
    }
1108
1109
    private bool _Sizable = true;
1110
    public bool Sizable
1111
    {
1112
        get { return _Sizable; }
1113
        set { _Sizable = value; }
1114
    }
1115
1116
    private Color _TransparencyKey;
1117
    public Color TransparencyKey
1118
    {
1119
        get
1120
        {
1121
            if (_IsParentForm && !_ControlMode)
1122
                return ParentForm.TransparencyKey;
1123
            else
1124
                return _TransparencyKey;
1125
        }
1126
        set
1127
        {
1128
            if (value == _TransparencyKey)
1129
                return;
1130
            _TransparencyKey = value;
1131
1132
            if (_IsParentForm && !_ControlMode)
1133
            {
1134
                ParentForm.TransparencyKey = value;
1135
                ColorHook();
1136
            }
1137
        }
1138
    }
1139
1140
    private FormBorderStyle _BorderStyle;
1141
    public FormBorderStyle BorderStyle
1142
    {
1143
        get
1144
        {
1145
            if (_IsParentForm && !_ControlMode)
1146
                return ParentForm.FormBorderStyle;
1147
            else
1148
                return _BorderStyle;
1149
        }
1150
        set
1151
        {
1152
            _BorderStyle = value;
1153
1154
            if (_IsParentForm && !_ControlMode)
1155
            {
1156
                ParentForm.FormBorderStyle = value;
1157
1158
                if (!(value == FormBorderStyle.None))
1159
                {
1160
                    Movable = false;
1161
                    Sizable = false;
1162
                }
1163
            }
1164
        }
1165
    }
1166
1167
    private FormStartPosition _StartPosition;
1168
    public FormStartPosition StartPosition
1169
    {
1170
        get
1171
        {
1172
            if (_IsParentForm && !_ControlMode)
1173
                return ParentForm.StartPosition;
1174
            else
1175
                return _StartPosition;
1176
        }
1177
        set
1178
        {
1179
            _StartPosition = value;
1180
1181
            if (_IsParentForm && !_ControlMode)
1182
            {
1183
                ParentForm.StartPosition = value;
1184
            }
1185
        }
1186
    }
1187
1188
    private bool _NoRounding;
1189
    public bool NoRounding
1190
    {
1191
        get { return _NoRounding; }
1192
        set
1193
        {
1194
            _NoRounding = value;
1195
            Invalidate();
1196
        }
1197
    }
1198
1199
    private Image _Image;
1200
    public Image Image
1201
    {
1202
        get { return _Image; }
1203
        set
1204
        {
1205
            if (value == null)
1206
                _ImageSize = Size.Empty;
1207
            else
1208
                _ImageSize = value.Size;
1209
1210
            _Image = value;
1211
            Invalidate();
1212
        }
1213
    }
1214
1215
    private Dictionary<string, Color> Items = new Dictionary<string, Color>();
1216
    public Bloom[] Colors
1217
    {
1218
        get
1219
        {
1220
            List<Bloom> T = new List<Bloom>();
1221
            Dictionary<string, Color>.Enumerator E = Items.GetEnumerator();
1222
1223
            while (E.MoveNext())
1224
            {
1225
                T.Add(new Bloom(E.Current.Key, E.Current.Value));
1226
            }
1227
1228
            return T.ToArray();
1229
        }
1230
        set
1231
        {
1232
            foreach (Bloom B in value)
1233
            {
1234
                if (Items.ContainsKey(B.Name))
1235
                    Items[B.Name] = B.Value;
1236
            }
1237
1238
            InvalidateCustimization();
1239
            ColorHook();
1240
            Invalidate();
1241
        }
1242
    }
1243
1244
    private string _Customization;
1245
    public string Customization
1246
    {
1247
        get { return _Customization; }
1248
        set
1249
        {
1250
            if (value == _Customization)
1251
                return;
1252
1253
            byte[] Data = null;
1254
            Bloom[] Items = Colors;
1255
1256
            try
1257
            {
1258
                Data = Convert.FromBase64String(value);
1259
                for (int I = 0; I <= Items.Length - 1; I++)
1260
                {
1261
                    Items[I].Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4));
1262
                }
1263
            }
1264
            catch
1265
            {
1266
                return;
1267
            }
1268
1269
            _Customization = value;
1270
1271
            Colors = Items;
1272
            ColorHook();
1273
            Invalidate();
1274
        }
1275
    }
1276
1277
    private bool _Transparent;
1278
    public bool Transparent
1279
    {
1280
        get { return _Transparent; }
1281
        set
1282
        {
1283
            _Transparent = value;
1284
            if (!(IsHandleCreated || _ControlMode))
1285
                return;
1286
1287
            if (!value && !(BackColor.A == 255))
1288
            {
1289
                throw new Exception("Unable to change value to false while a transparent BackColor is in use.");
1290
            }
1291
1292
            SetStyle(ControlStyles.Opaque, !value);
1293
            SetStyle(ControlStyles.SupportsTransparentBackColor, value);
1294
1295
            InvalidateBitmap();
1296
            Invalidate();
1297
        }
1298
    }
1299
1300
    #endregion
1301
1302
    #region " Private Properties "
1303
1304
    private Size _ImageSize;
1305
    protected Size ImageSize
1306
    {
1307
        get { return _ImageSize; }
1308
    }
1309
1310
    private bool _IsParentForm;
1311
    protected bool IsParentForm
1312
    {
1313
        get { return _IsParentForm; }
1314
    }
1315
1316
    protected bool IsParentMdi
1317
    {
1318
        get
1319
        {
1320
            if (Parent == null)
1321
                return false;
1322
            return Parent.Parent != null;
1323
        }
1324
    }
1325
1326
    private int _LockWidth;
1327
    protected int LockWidth
1328
    {
1329
        get { return _LockWidth; }
1330
        set
1331
        {
1332
            _LockWidth = value;
1333
            if (!(LockWidth == 0) && IsHandleCreated)
1334
                Width = LockWidth;
1335
        }
1336
    }
1337
1338
    private int _LockHeight;
1339
    protected int LockHeight
1340
    {
1341
        get { return _LockHeight; }
1342
        set
1343
        {
1344
            _LockHeight = value;
1345
            if (!(LockHeight == 0) && IsHandleCreated)
1346
                Height = LockHeight;
1347
        }
1348
    }
1349
1350
    private int _Header = 24;
1351
    protected int Header
1352
    {
1353
        get { return _Header; }
1354
        set
1355
        {
1356
            _Header = value;
1357
1358
            if (!_ControlMode)
1359
            {
1360
                Frame = new Rectangle(7, 7, Width - 14, value - 7);
1361
                Invalidate();
1362
            }
1363
        }
1364
    }
1365
1366
    private bool _ControlMode;
1367
    protected bool ControlMode
1368
    {
1369
        get { return _ControlMode; }
1370
        set
1371
        {
1372
            _ControlMode = value;
1373
1374
            Transparent = _Transparent;
1375
            if (_Transparent && _BackColor)
1376
                BackColor = Color.Transparent;
1377
1378
            InvalidateBitmap();
1379
            Invalidate();
1380
        }
1381
    }
1382
1383
    private bool _IsAnimated;
1384
    protected bool IsAnimated
1385
    {
1386
        get { return _IsAnimated; }
1387
        set
1388
        {
1389
            _IsAnimated = value;
1390
            InvalidateTimer();
1391
        }
1392
    }
1393
1394
    #endregion
1395
1396
1397
    #region " Property Helpers "
1398
1399
    protected Pen GetPen(string name)
1400
    {
1401
        return new Pen(Items[name]);
1402
    }
1403
    protected Pen GetPen(string name, float width)
1404
    {
1405
        return new Pen(Items[name], width);
1406
    }
1407
1408
    protected SolidBrush GetBrush(string name)
1409
    {
1410
        return new SolidBrush(Items[name]);
1411
    }
1412
1413
    protected Color GetColor(string name)
1414
    {
1415
        return Items[name];
1416
    }
1417
1418
    protected void SetColor(string name, Color value)
1419
    {
1420
        if (Items.ContainsKey(name))
1421
            Items[name] = value;
1422
        else
1423
            Items.Add(name, value);
1424
    }
1425
    protected void SetColor(string name, byte r, byte g, byte b)
1426
    {
1427
        SetColor(name, Color.FromArgb(r, g, b));
1428
    }
1429
    protected void SetColor(string name, byte a, byte r, byte g, byte b)
1430
    {
1431
        SetColor(name, Color.FromArgb(a, r, g, b));
1432
    }
1433
    protected void SetColor(string name, byte a, Color value)
1434
    {
1435
        SetColor(name, Color.FromArgb(a, value));
1436
    }
1437
1438
    private void InvalidateBitmap()
1439
    {
1440
        if (_Transparent && _ControlMode)
1441
        {
1442
            if (Width == 0 || Height == 0)
1443
                return;
1444
            B = new Bitmap(Width, Height, PixelFormat.Format32bppPArgb);
1445
            G = Graphics.FromImage(B);
1446
        }
1447
        else
1448
        {
1449
            G = null;
1450
            B = null;
1451
        }
1452
    }
1453
1454
    private void InvalidateCustimization()
1455
    {
1456
        MemoryStream M = new MemoryStream(Items.Count * 4);
1457
1458
        foreach (Bloom B in Colors)
1459
        {
1460
            M.Write(BitConverter.GetBytes(B.Value.ToArgb()), 0, 4);
1461
        }
1462
1463
        M.Close();
1464
        _Customization = Convert.ToBase64String(M.ToArray());
1465
    }
1466
1467
    private void InvalidateTimer()
1468
    {
1469
        if (DesignMode || !DoneCreation)
1470
            return;
1471
1472
        if (_IsAnimated)
1473
        {
1474
            ThemeShare.AddAnimationCallback(DoAnimation);
1475
        }
1476
        else
1477
        {
1478
            ThemeShare.RemoveAnimationCallback(DoAnimation);
1479
        }
1480
    }
1481
1482
    #endregion
1483
1484
1485
    #region " User Hooks "
1486
1487
    protected abstract void ColorHook();
1488
    protected abstract void PaintHook();
1489
1490
    protected virtual void OnCreation()
1491
    {
1492
    }
1493
1494
    protected virtual void OnAnimation()
1495
    {
1496
    }
1497
1498
    #endregion
1499
1500
1501
    #region " Offset "
1502
1503
    private Rectangle OffsetReturnRectangle;
1504
    protected Rectangle Offset(Rectangle r, int amount)
1505
    {
1506
        OffsetReturnRectangle = new Rectangle(r.X + amount, r.Y + amount, r.Width - (amount * 2), r.Height - (amount * 2));
1507
        return OffsetReturnRectangle;
1508
    }
1509
1510
    private Size OffsetReturnSize;
1511
    protected Size Offset(Size s, int amount)
1512
    {
1513
        OffsetReturnSize = new Size(s.Width + amount, s.Height + amount);
1514
        return OffsetReturnSize;
1515
    }
1516
1517
    private Point OffsetReturnPoint;
1518
    protected Point Offset(Point p, int amount)
1519
    {
1520
        OffsetReturnPoint = new Point(p.X + amount, p.Y + amount);
1521
        return OffsetReturnPoint;
1522
    }
1523
1524
    #endregion
1525
1526
    #region " Center "
1527
1528
1529
    private Point CenterReturn;
1530
    protected Point Center(Rectangle p, Rectangle c)
1531
    {
1532
        CenterReturn = new Point((p.Width / 2 - c.Width / 2) + p.X + c.X, (p.Height / 2 - c.Height / 2) + p.Y + c.Y);
1533
        return CenterReturn;
1534
    }
1535
    protected Point Center(Rectangle p, Size c)
1536
    {
1537
        CenterReturn = new Point((p.Width / 2 - c.Width / 2) + p.X, (p.Height / 2 - c.Height / 2) + p.Y);
1538
        return CenterReturn;
1539
    }
1540
1541
    protected Point Center(Rectangle child)
1542
    {
1543
        return Center(Width, Height, child.Width, child.Height);
1544
    }
1545
    protected Point Center(Size child)
1546
    {
1547
        return Center(Width, Height, child.Width, child.Height);
1548
    }
1549
    protected Point Center(int childWidth, int childHeight)
1550
    {
1551
        return Center(Width, Height, childWidth, childHeight);
1552
    }
1553
1554
    protected Point Center(Size p, Size c)
1555
    {
1556
        return Center(p.Width, p.Height, c.Width, c.Height);
1557
    }
1558
1559
    protected Point Center(int pWidth, int pHeight, int cWidth, int cHeight)
1560
    {
1561
        CenterReturn = new Point(pWidth / 2 - cWidth / 2, pHeight / 2 - cHeight / 2);
1562
        return CenterReturn;
1563
    }
1564
1565
    #endregion
1566
1567
    #region " Measure "
1568
1569
    private Bitmap MeasureBitmap;
1570
1571
    private Graphics MeasureGraphics;
1572
    protected Size Measure()
1573
    {
1574
        lock (MeasureGraphics)
1575
        {
1576
            return MeasureGraphics.MeasureString(Text, Font, Width).ToSize();
1577
        }
1578
    }
1579
    protected Size Measure(string text)
1580
    {
1581
        lock (MeasureGraphics)
1582
        {
1583
            return MeasureGraphics.MeasureString(text, Font, Width).ToSize();
1584
        }
1585
    }
1586
1587
    #endregion
1588
1589
1590
    #region " DrawPixel "
1591
1592
1593
    private SolidBrush DrawPixelBrush;
1594
    protected void DrawPixel(Color c1, int x, int y)
1595
    {
1596
        if (_Transparent)
1597
        {
1598
            B.SetPixel(x, y, c1);
1599
        }
1600
        else
1601
        {
1602
            DrawPixelBrush = new SolidBrush(c1);
1603
            G.FillRectangle(DrawPixelBrush, x, y, 1, 1);
1604
        }
1605
    }
1606
1607
    #endregion
1608
1609
    #region " DrawCorners "
1610
1611
1612
    private SolidBrush DrawCornersBrush;
1613
    protected void DrawCorners(Color c1, int offset)
1614
    {
1615
        DrawCorners(c1, 0, 0, Width, Height, offset);
1616
    }
1617
    protected void DrawCorners(Color c1, Rectangle r1, int offset)
1618
    {
1619
        DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height, offset);
1620
    }
1621
    protected void DrawCorners(Color c1, int x, int y, int width, int height, int offset)
1622
    {
1623
        DrawCorners(c1, x + offset, y + offset, width - (offset * 2), height - (offset * 2));
1624
    }
1625
1626
    protected void DrawCorners(Color c1)
1627
    {
1628
        DrawCorners(c1, 0, 0, Width, Height);
1629
    }
1630
    protected void DrawCorners(Color c1, Rectangle r1)
1631
    {
1632
        DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height);
1633
    }
1634
    protected void DrawCorners(Color c1, int x, int y, int width, int height)
1635
    {
1636
        if (_NoRounding)
1637
            return;
1638
1639
        if (_Transparent)
1640
        {
1641
            B.SetPixel(x, y, c1);
1642
            B.SetPixel(x + (width - 1), y, c1);
1643
            B.SetPixel(x, y + (height - 1), c1);
1644
            B.SetPixel(x + (width - 1), y + (height - 1), c1);
1645
        }
1646
        else
1647
        {
1648
            DrawCornersBrush = new SolidBrush(c1);
1649
            G.FillRectangle(DrawCornersBrush, x, y, 1, 1);
1650
            G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1);
1651
            G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1);
1652
            G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1);
1653
        }
1654
    }
1655
1656
    #endregion
1657
1658
    #region " DrawBorders "
1659
1660
    protected void DrawBorders(Pen p1, int offset)
1661
    {
1662
        DrawBorders(p1, 0, 0, Width, Height, offset);
1663
    }
1664
    protected void DrawBorders(Pen p1, Rectangle r, int offset)
1665
    {
1666
        DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset);
1667
    }
1668
    protected void DrawBorders(Pen p1, int x, int y, int width, int height, int offset)
1669
    {
1670
        DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2));
1671
    }
1672
1673
    protected void DrawBorders(Pen p1)
1674
    {
1675
        DrawBorders(p1, 0, 0, Width, Height);
1676
    }
1677
    protected void DrawBorders(Pen p1, Rectangle r)
1678
    {
1679
        DrawBorders(p1, r.X, r.Y, r.Width, r.Height);
1680
    }
1681
    protected void DrawBorders(Pen p1, int x, int y, int width, int height)
1682
    {
1683
        G.DrawRectangle(p1, x, y, width - 1, height - 1);
1684
    }
1685
1686
    #endregion
1687
1688
    #region " DrawText "
1689
1690
    private Point DrawTextPoint;
1691
1692
    private Size DrawTextSize;
1693
    protected void DrawText(Brush b1, HorizontalAlignment a, int x, int y)
1694
    {
1695
        DrawText(b1, Text, a, x, y);
1696
    }
1697
    protected void DrawText(Brush b1, string text, HorizontalAlignment a, int x, int y)
1698
    {
1699
        if (text.Length == 0)
1700
            return;
1701
1702
        DrawTextSize = Measure(text);
1703
        DrawTextPoint = new Point(Width / 2 - DrawTextSize.Width / 2, Header / 2 - DrawTextSize.Height / 2);
1704
1705
        switch (a)
1706
        {
1707
            case HorizontalAlignment.Left:
1708
                G.DrawString(text, Font, b1, x, DrawTextPoint.Y + y);
1709
                break;
1710
            case HorizontalAlignment.Center:
1711
                G.DrawString(text, Font, b1, DrawTextPoint.X + x, DrawTextPoint.Y + y);
1712
                break;
1713
            case HorizontalAlignment.Right:
1714
                G.DrawString(text, Font, b1, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y);
1715
                break;
1716
        }
1717
    }
1718
1719
    protected void DrawText(Brush b1, Point p1)
1720
    {
1721
        if (Text.Length == 0)
1722
            return;
1723
        G.DrawString(Text, Font, b1, p1);
1724
    }
1725
    protected void DrawText(Brush b1, int x, int y)
1726
    {
1727
        if (Text.Length == 0)
1728
            return;
1729
        G.DrawString(Text, Font, b1, x, y);
1730
    }
1731
1732
    #endregion
1733
1734
    #region " DrawImage "
1735
1736
1737
    private Point DrawImagePoint;
1738
    protected void DrawImage(HorizontalAlignment a, int x, int y)
1739
    {
1740
        DrawImage(_Image, a, x, y);
1741
    }
1742
    protected void DrawImage(Image image, HorizontalAlignment a, int x, int y)
1743
    {
1744
        if (image == null)
1745
            return;
1746
        DrawImagePoint = new Point(Width / 2 - image.Width / 2, Header / 2 - image.Height / 2);
1747
1748
        switch (a)
1749
        {
1750
            case HorizontalAlignment.Left:
1751
                G.DrawImage(image, x, DrawImagePoint.Y + y, image.Width, image.Height);
1752
                break;
1753
            case HorizontalAlignment.Center:
1754
                G.DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y, image.Width, image.Height);
1755
                break;
1756
            case HorizontalAlignment.Right:
1757
                G.DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y, image.Width, image.Height);
1758
                break;
1759
        }
1760
    }
1761
1762
    protected void DrawImage(Point p1)
1763
    {
1764
        DrawImage(_Image, p1.X, p1.Y);
1765
    }
1766
    protected void DrawImage(int x, int y)
1767
    {
1768
        DrawImage(_Image, x, y);
1769
    }
1770
1771
    protected void DrawImage(Image image, Point p1)
1772
    {
1773
        DrawImage(image, p1.X, p1.Y);
1774
    }
1775
    protected void DrawImage(Image image, int x, int y)
1776
    {
1777
        if (image == null)
1778
            return;
1779
        G.DrawImage(image, x, y, image.Width, image.Height);
1780
    }
1781
1782
    #endregion
1783
1784
    #region " DrawGradient "
1785
1786
    private LinearGradientBrush DrawGradientBrush;
1787
1788
    private Rectangle DrawGradientRectangle;
1789
    protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height)
1790
    {
1791
        DrawGradientRectangle = new Rectangle(x, y, width, height);
1792
        DrawGradient(blend, DrawGradientRectangle);
1793
    }
1794
    protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height, float angle)
1795
    {
1796
        DrawGradientRectangle = new Rectangle(x, y, width, height);
1797
        DrawGradient(blend, DrawGradientRectangle, angle);
1798
    }
1799
1800
    protected void DrawGradient(ColorBlend blend, Rectangle r)
1801
    {
1802
        DrawGradientBrush = new LinearGradientBrush(r, Color.Empty, Color.Empty, 90f);
1803
        DrawGradientBrush.InterpolationColors = blend;
1804
        G.FillRectangle(DrawGradientBrush, r);
1805
    }
1806
    protected void DrawGradient(ColorBlend blend, Rectangle r, float angle)
1807
    {
1808
        DrawGradientBrush = new LinearGradientBrush(r, Color.Empty, Color.Empty, angle);
1809
        DrawGradientBrush.InterpolationColors = blend;
1810
        G.FillRectangle(DrawGradientBrush, r);
1811
    }
1812
1813
1814
    protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height)
1815
    {
1816
        DrawGradientRectangle = new Rectangle(x, y, width, height);
1817
        DrawGradient(c1, c2, DrawGradientRectangle);
1818
    }
1819
    protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height, float angle)
1820
    {
1821
        DrawGradientRectangle = new Rectangle(x, y, width, height);
1822
        DrawGradient(c1, c2, DrawGradientRectangle, angle);
1823
    }
1824
1825
    protected void DrawGradient(Color c1, Color c2, Rectangle r)
1826
    {
1827
        DrawGradientBrush = new LinearGradientBrush(r, c1, c2, 90f);
1828
        G.FillRectangle(DrawGradientBrush, r);
1829
    }
1830
    protected void DrawGradient(Color c1, Color c2, Rectangle r, float angle)
1831
    {
1832
        DrawGradientBrush = new LinearGradientBrush(r, c1, c2, angle);
1833
        G.FillRectangle(DrawGradientBrush, r);
1834
    }
1835
1836
    #endregion
1837
1838
    #region " DrawRadial "
1839
1840
    private GraphicsPath DrawRadialPath;
1841
    private PathGradientBrush DrawRadialBrush1;
1842
    private LinearGradientBrush DrawRadialBrush2;
1843
1844
    private Rectangle DrawRadialRectangle;
1845
    public void DrawRadial(ColorBlend blend, int x, int y, int width, int height)
1846
    {
1847
        DrawRadialRectangle = new Rectangle(x, y, width, height);
1848
        DrawRadial(blend, DrawRadialRectangle, width / 2, height / 2);
1849
    }
1850
    public void DrawRadial(ColorBlend blend, int x, int y, int width, int height, Point center)
1851
    {
1852
        DrawRadialRectangle = new Rectangle(x, y, width, height);
1853
        DrawRadial(blend, DrawRadialRectangle, center.X, center.Y);
1854
    }
1855
    public void DrawRadial(ColorBlend blend, int x, int y, int width, int height, int cx, int cy)
1856
    {
1857
        DrawRadialRectangle = new Rectangle(x, y, width, height);
1858
        DrawRadial(blend, DrawRadialRectangle, cx, cy);
1859
    }
1860
1861
    public void DrawRadial(ColorBlend blend, Rectangle r)
1862
    {
1863
        DrawRadial(blend, r, r.Width / 2, r.Height / 2);
1864
    }
1865
    public void DrawRadial(ColorBlend blend, Rectangle r, Point center)
1866
    {
1867
        DrawRadial(blend, r, center.X, center.Y);
1868
    }
1869
    public void DrawRadial(ColorBlend blend, Rectangle r, int cx, int cy)
1870
    {
1871
        DrawRadialPath.Reset();
1872
        DrawRadialPath.AddEllipse(r.X, r.Y, r.Width - 1, r.Height - 1);
1873
1874
        DrawRadialBrush1 = new PathGradientBrush(DrawRadialPath);
1875
        DrawRadialBrush1.CenterPoint = new Point(r.X + cx, r.Y + cy);
1876
        DrawRadialBrush1.InterpolationColors = blend;
1877
1878
        if (G.SmoothingMode == SmoothingMode.AntiAlias)
1879
        {
1880
            G.FillEllipse(DrawRadialBrush1, r.X + 1, r.Y + 1, r.Width - 3, r.Height - 3);
1881
        }
1882
        else
1883
        {
1884
            G.FillEllipse(DrawRadialBrush1, r);
1885
        }
1886
    }
1887
1888
1889
    protected void DrawRadial(Color c1, Color c2, int x, int y, int width, int height)
1890
    {
1891
        DrawRadialRectangle = new Rectangle(x, y, width, height);
1892
        DrawRadial(c1, c2, DrawGradientRectangle);
1893
    }
1894
    protected void DrawRadial(Color c1, Color c2, int x, int y, int width, int height, float angle)
1895
    {
1896
        DrawRadialRectangle = new Rectangle(x, y, width, height);
1897
        DrawRadial(c1, c2, DrawGradientRectangle, angle);
1898
    }
1899
1900
    protected void DrawRadial(Color c1, Color c2, Rectangle r)
1901
    {
1902
        DrawRadialBrush2 = new LinearGradientBrush(r, c1, c2, 90f);
1903
        G.FillRectangle(DrawGradientBrush, r);
1904
    }
1905
    protected void DrawRadial(Color c1, Color c2, Rectangle r, float angle)
1906
    {
1907
        DrawRadialBrush2 = new LinearGradientBrush(r, c1, c2, angle);
1908
        G.FillEllipse(DrawGradientBrush, r);
1909
    }
1910
1911
    #endregion
1912
1913
    #region " CreateRound "
1914
1915
    private GraphicsPath CreateRoundPath;
1916
1917
    private Rectangle CreateRoundRectangle;
1918
    public GraphicsPath CreateRound(int x, int y, int width, int height, int slope)
1919
    {
1920
        CreateRoundRectangle = new Rectangle(x, y, width, height);
1921
        return CreateRound(CreateRoundRectangle, slope);
1922
    }
1923
1924
    public GraphicsPath CreateRound(Rectangle r, int slope)
1925
    {
1926
        CreateRoundPath = new GraphicsPath(FillMode.Winding);
1927
        CreateRoundPath.AddArc(r.X, r.Y, slope, slope, 180f, 90f);
1928
        CreateRoundPath.AddArc(r.Right - slope, r.Y, slope, slope, 270f, 90f);
1929
        CreateRoundPath.AddArc(r.Right - slope, r.Bottom - slope, slope, slope, 0f, 90f);
1930
        CreateRoundPath.AddArc(r.X, r.Bottom - slope, slope, slope, 90f, 90f);
1931
        CreateRoundPath.CloseFigure();
1932
        return CreateRoundPath;
1933
    }
1934
1935
    #endregion
1936
1937
}
1938
1939
abstract class ThemeControl154 : Control
1940
{
1941
1942
1943
    #region " Initialization "
1944
1945
    protected Graphics G;
1946
1947
    protected Bitmap B;
1948
    public ThemeControl154()
1949
    {
1950
        SetStyle((ControlStyles)139270, true);
1951
1952
        _ImageSize = Size.Empty;
1953
        Font = new Font("Verdana", 8);
1954
1955
        MeasureBitmap = new Bitmap(1, 1);
1956
        MeasureGraphics = Graphics.FromImage(MeasureBitmap);
1957
1958
        DrawRadialPath = new GraphicsPath();
1959
1960
        InvalidateCustimization();
1961
        //Remove?
1962
    }
1963
1964
    protected override sealed void OnHandleCreated(EventArgs e)
1965
    {
1966
        InvalidateCustimization();
1967
        ColorHook();
1968
1969
        if (!(_LockWidth == 0))
1970
            Width = _LockWidth;
1971
        if (!(_LockHeight == 0))
1972
            Height = _LockHeight;
1973
1974
        Transparent = _Transparent;
1975
        if (_Transparent && _BackColor)
1976
            BackColor = Color.Transparent;
1977
1978
        base.OnHandleCreated(e);
1979
    }
1980
1981
    private bool DoneCreation;
1982
    protected override sealed void OnParentChanged(EventArgs e)
1983
    {
1984
        if (Parent != null)
1985
        {
1986
            OnCreation();
1987
            DoneCreation = true;
1988
            InvalidateTimer();
1989
        }
1990
1991
        base.OnParentChanged(e);
1992
    }
1993
1994
    #endregion
1995
1996
    private void DoAnimation(bool i)
1997
    {
1998
        OnAnimation();
1999
        if (i)
2000
            Invalidate();
2001
    }
2002
2003
    protected override sealed void OnPaint(PaintEventArgs e)
2004
    {
2005
        if (Width == 0 || Height == 0)
2006
            return;
2007
2008
        if (_Transparent)
2009
        {
2010
            PaintHook();
2011
            e.Graphics.DrawImage(B, 0, 0);
2012
        }
2013
        else
2014
        {
2015
            G = e.Graphics;
2016
            PaintHook();
2017
        }
2018
    }
2019
2020
    protected override void OnHandleDestroyed(EventArgs e)
2021
    {
2022
        ThemeShare.RemoveAnimationCallback(DoAnimation);
2023
        base.OnHandleDestroyed(e);
2024
    }
2025
2026
    #region " Size Handling "
2027
2028
    protected override sealed void OnSizeChanged(EventArgs e)
2029
    {
2030
        if (_Transparent)
2031
        {
2032
            InvalidateBitmap();
2033
        }
2034
2035
        Invalidate();
2036
        base.OnSizeChanged(e);
2037
    }
2038
2039
    protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
2040
    {
2041
        if (!(_LockWidth == 0))
2042
            width = _LockWidth;
2043
        if (!(_LockHeight == 0))
2044
            height = _LockHeight;
2045
        base.SetBoundsCore(x, y, width, height, specified);
2046
    }
2047
2048
    #endregion
2049
2050
    #region " State Handling "
2051
2052
    private bool InPosition;
2053
    protected override void OnMouseEnter(EventArgs e)
2054
    {
2055
        InPosition = true;
2056
        SetState(MouseState.Over);
2057
        base.OnMouseEnter(e);
2058
    }
2059
2060
    protected override void OnMouseUp(MouseEventArgs e)
2061
    {
2062
        if (InPosition)
2063
            SetState(MouseState.Over);
2064
        base.OnMouseUp(e);
2065
    }
2066
2067
    protected override void OnMouseDown(MouseEventArgs e)
2068
    {
2069
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
2070
            SetState(MouseState.Down);
2071
        base.OnMouseDown(e);
2072
    }
2073
2074
    protected override void OnMouseLeave(EventArgs e)
2075
    {
2076
        InPosition = false;
2077
        SetState(MouseState.None);
2078
        base.OnMouseLeave(e);
2079
    }
2080
2081
    protected override void OnEnabledChanged(EventArgs e)
2082
    {
2083
        if (Enabled)
2084
            SetState(MouseState.None);
2085
        else
2086
            SetState(MouseState.Block);
2087
        base.OnEnabledChanged(e);
2088
    }
2089
2090
    protected MouseState State;
2091
    private void SetState(MouseState current)
2092
    {
2093
        State = current;
2094
        Invalidate();
2095
    }
2096
2097
    #endregion
2098
2099
2100
    #region " Base Properties "
2101
2102
    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2103
    public override Color ForeColor
2104
    {
2105
        get { return Color.Empty; }
2106
        set { }
2107
    }
2108
    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2109
    public override Image BackgroundImage
2110
    {
2111
        get { return null; }
2112
        set { }
2113
    }
2114
    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2115
    public override ImageLayout BackgroundImageLayout
2116
    {
2117
        get { return ImageLayout.None; }
2118
        set { }
2119
    }
2120
2121
    public override string Text
2122
    {
2123
        get { return base.Text; }
2124
        set
2125
        {
2126
            base.Text = value;
2127
            Invalidate();
2128
        }
2129
    }
2130
    public override Font Font
2131
    {
2132
        get { return base.Font; }
2133
        set
2134
        {
2135
            base.Font = value;
2136
            Invalidate();
2137
        }
2138
    }
2139
2140
    private bool _BackColor;
2141
    [Category("Misc")]
2142
    public override Color BackColor
2143
    {
2144
        get { return base.BackColor; }
2145
        set
2146
        {
2147
            if (!IsHandleCreated && value == Color.Transparent)
2148
            {
2149
                _BackColor = true;
2150
                return;
2151
            }
2152
2153
            base.BackColor = value;
2154
            if (Parent != null)
2155
                ColorHook();
2156
        }
2157
    }
2158
2159
    #endregion
2160
2161
    #region " Public Properties "
2162
2163
    private bool _NoRounding;
2164
    public bool NoRounding
2165
    {
2166
        get { return _NoRounding; }
2167
        set
2168
        {
2169
            _NoRounding = value;
2170
            Invalidate();
2171
        }
2172
    }
2173
2174
    private Image _Image;
2175
    public Image Image
2176
    {
2177
        get { return _Image; }
2178
        set
2179
        {
2180
            if (value == null)
2181
            {
2182
                _ImageSize = Size.Empty;
2183
            }
2184
            else
2185
            {
2186
                _ImageSize = value.Size;
2187
            }
2188
2189
            _Image = value;
2190
            Invalidate();
2191
        }
2192
    }
2193
2194
    private bool _Transparent;
2195
    public bool Transparent
2196
    {
2197
        get { return _Transparent; }
2198
        set
2199
        {
2200
            _Transparent = value;
2201
            if (!IsHandleCreated)
2202
                return;
2203
2204
            if (!value && !(BackColor.A == 255))
2205
            {
2206
                throw new Exception("Unable to change value to false while a transparent BackColor is in use.");
2207
            }
2208
2209
            SetStyle(ControlStyles.Opaque, !value);
2210
            SetStyle(ControlStyles.SupportsTransparentBackColor, value);
2211
2212
            if (value)
2213
                InvalidateBitmap();
2214
            else
2215
                B = null;
2216
            Invalidate();
2217
        }
2218
    }
2219
2220
    private Dictionary<string, Color> Items = new Dictionary<string, Color>();
2221
    public Bloom[] Colors
2222
    {
2223
        get
2224
        {
2225
            List<Bloom> T = new List<Bloom>();
2226
            Dictionary<string, Color>.Enumerator E = Items.GetEnumerator();
2227
2228
            while (E.MoveNext())
2229
            {
2230
                T.Add(new Bloom(E.Current.Key, E.Current.Value));
2231
            }
2232
2233
            return T.ToArray();
2234
        }
2235
        set
2236
        {
2237
            foreach (Bloom B in value)
2238
            {
2239
                if (Items.ContainsKey(B.Name))
2240
                    Items[B.Name] = B.Value;
2241
            }
2242
2243
            InvalidateCustimization();
2244
            ColorHook();
2245
            Invalidate();
2246
        }
2247
    }
2248
2249
    private string _Customization;
2250
    public string Customization
2251
    {
2252
        get { return _Customization; }
2253
        set
2254
        {
2255
            if (value == _Customization)
2256
                return;
2257
2258
            byte[] Data = null;
2259
            Bloom[] Items = Colors;
2260
2261
            try
2262
            {
2263
                Data = Convert.FromBase64String(value);
2264
                for (int I = 0; I <= Items.Length - 1; I++)
2265
                {
2266
                    Items[I].Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4));
2267
                }
2268
            }
2269
            catch
2270
            {
2271
                return;
2272
            }
2273
2274
            _Customization = value;
2275
2276
            Colors = Items;
2277
            ColorHook();
2278
            Invalidate();
2279
        }
2280
    }
2281
2282
    #endregion
2283
2284
    #region " Private Properties "
2285
2286
    private Size _ImageSize;
2287
    protected Size ImageSize
2288
    {
2289
        get { return _ImageSize; }
2290
    }
2291
2292
    private int _LockWidth;
2293
    protected int LockWidth
2294
    {
2295
        get { return _LockWidth; }
2296
        set
2297
        {
2298
            _LockWidth = value;
2299
            if (!(LockWidth == 0) && IsHandleCreated)
2300
                Width = LockWidth;
2301
        }
2302
    }
2303
2304
    private int _LockHeight;
2305
    protected int LockHeight
2306
    {
2307
        get { return _LockHeight; }
2308
        set
2309
        {
2310
            _LockHeight = value;
2311
            if (!(LockHeight == 0) && IsHandleCreated)
2312
                Height = LockHeight;
2313
        }
2314
    }
2315
2316
    private bool _IsAnimated;
2317
    protected bool IsAnimated
2318
    {
2319
        get { return _IsAnimated; }
2320
        set
2321
        {
2322
            _IsAnimated = value;
2323
            InvalidateTimer();
2324
        }
2325
    }
2326
2327
    #endregion
2328
2329
2330
    #region " Property Helpers "
2331
2332
    protected Pen GetPen(string name)
2333
    {
2334
        return new Pen(Items[name]);
2335
    }
2336
    protected Pen GetPen(string name, float width)
2337
    {
2338
        return new Pen(Items[name], width);
2339
    }
2340
2341
    protected SolidBrush GetBrush(string name)
2342
    {
2343
        return new SolidBrush(Items[name]);
2344
    }
2345
2346
    protected Color GetColor(string name)
2347
    {
2348
        return Items[name];
2349
    }
2350
2351
    protected void SetColor(string name, Color value)
2352
    {
2353
        if (Items.ContainsKey(name))
2354
            Items[name] = value;
2355
        else
2356
            Items.Add(name, value);
2357
    }
2358
    protected void SetColor(string name, byte r, byte g, byte b)
2359
    {
2360
        SetColor(name, Color.FromArgb(r, g, b));
2361
    }
2362
    protected void SetColor(string name, byte a, byte r, byte g, byte b)
2363
    {
2364
        SetColor(name, Color.FromArgb(a, r, g, b));
2365
    }
2366
    protected void SetColor(string name, byte a, Color value)
2367
    {
2368
        SetColor(name, Color.FromArgb(a, value));
2369
    }
2370
2371
    private void InvalidateBitmap()
2372
    {
2373
        if (Width == 0 || Height == 0)
2374
            return;
2375
        B = new Bitmap(Width, Height, PixelFormat.Format32bppPArgb);
2376
        G = Graphics.FromImage(B);
2377
    }
2378
2379
    private void InvalidateCustimization()
2380
    {
2381
        MemoryStream M = new MemoryStream(Items.Count * 4);
2382
2383
        foreach (Bloom B in Colors)
2384
        {
2385
            M.Write(BitConverter.GetBytes(B.Value.ToArgb()), 0, 4);
2386
        }
2387
2388
        M.Close();
2389
        _Customization = Convert.ToBase64String(M.ToArray());
2390
    }
2391
2392
    private void InvalidateTimer()
2393
    {
2394
        if (DesignMode || !DoneCreation)
2395
            return;
2396
2397
        if (_IsAnimated)
2398
        {
2399
            ThemeShare.AddAnimationCallback(DoAnimation);
2400
        }
2401
        else
2402
        {
2403
            ThemeShare.RemoveAnimationCallback(DoAnimation);
2404
        }
2405
    }
2406
    #endregion
2407
2408
2409
    #region " User Hooks "
2410
2411
    protected abstract void ColorHook();
2412
    protected abstract void PaintHook();
2413
2414
    protected virtual void OnCreation()
2415
    {
2416
    }
2417
2418
    protected virtual void OnAnimation()
2419
    {
2420
    }
2421
2422
    #endregion
2423
2424
2425
    #region " Offset "
2426
2427
    private Rectangle OffsetReturnRectangle;
2428
    protected Rectangle Offset(Rectangle r, int amount)
2429
    {
2430
        OffsetReturnRectangle = new Rectangle(r.X + amount, r.Y + amount, r.Width - (amount * 2), r.Height - (amount * 2));
2431
        return OffsetReturnRectangle;
2432
    }
2433
2434
    private Size OffsetReturnSize;
2435
    protected Size Offset(Size s, int amount)
2436
    {
2437
        OffsetReturnSize = new Size(s.Width + amount, s.Height + amount);
2438
        return OffsetReturnSize;
2439
    }
2440
2441
    private Point OffsetReturnPoint;
2442
    protected Point Offset(Point p, int amount)
2443
    {
2444
        OffsetReturnPoint = new Point(p.X + amount, p.Y + amount);
2445
        return OffsetReturnPoint;
2446
    }
2447
2448
    #endregion
2449
2450
    #region " Center "
2451
2452
2453
    private Point CenterReturn;
2454
    protected Point Center(Rectangle p, Rectangle c)
2455
    {
2456
        CenterReturn = new Point((p.Width / 2 - c.Width / 2) + p.X + c.X, (p.Height / 2 - c.Height / 2) + p.Y + c.Y);
2457
        return CenterReturn;
2458
    }
2459
    protected Point Center(Rectangle p, Size c)
2460
    {
2461
        CenterReturn = new Point((p.Width / 2 - c.Width / 2) + p.X, (p.Height / 2 - c.Height / 2) + p.Y);
2462
        return CenterReturn;
2463
    }
2464
2465
    protected Point Center(Rectangle child)
2466
    {
2467
        return Center(Width, Height, child.Width, child.Height);
2468
    }
2469
    protected Point Center(Size child)
2470
    {
2471
        return Center(Width, Height, child.Width, child.Height);
2472
    }
2473
    protected Point Center(int childWidth, int childHeight)
2474
    {
2475
        return Center(Width, Height, childWidth, childHeight);
2476
    }
2477
2478
    protected Point Center(Size p, Size c)
2479
    {
2480
        return Center(p.Width, p.Height, c.Width, c.Height);
2481
    }
2482
2483
    protected Point Center(int pWidth, int pHeight, int cWidth, int cHeight)
2484
    {
2485
        CenterReturn = new Point(pWidth / 2 - cWidth / 2, pHeight / 2 - cHeight / 2);
2486
        return CenterReturn;
2487
    }
2488
2489
    #endregion
2490
2491
    #region " Measure "
2492
2493
    private Bitmap MeasureBitmap;
2494
    //TODO: Potential issues during multi-threading.
2495
    private Graphics MeasureGraphics;
2496
2497
    protected Size Measure()
2498
    {
2499
        return MeasureGraphics.MeasureString(Text, Font, Width).ToSize();
2500
    }
2501
    protected Size Measure(string text)
2502
    {
2503
        return MeasureGraphics.MeasureString(text, Font, Width).ToSize();
2504
    }
2505
2506
    #endregion
2507
2508
2509
    #region " DrawPixel "
2510
2511
2512
    private SolidBrush DrawPixelBrush;
2513
    protected void DrawPixel(Color c1, int x, int y)
2514
    {
2515
        if (_Transparent)
2516
        {
2517
            B.SetPixel(x, y, c1);
2518
        }
2519
        else
2520
        {
2521
            DrawPixelBrush = new SolidBrush(c1);
2522
            G.FillRectangle(DrawPixelBrush, x, y, 1, 1);
2523
        }
2524
    }
2525
2526
    #endregion
2527
2528
    #region " DrawCorners "
2529
2530
2531
    private SolidBrush DrawCornersBrush;
2532
    protected void DrawCorners(Color c1, int offset)
2533
    {
2534
        DrawCorners(c1, 0, 0, Width, Height, offset);
2535
    }
2536
    protected void DrawCorners(Color c1, Rectangle r1, int offset)
2537
    {
2538
        DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height, offset);
2539
    }
2540
    protected void DrawCorners(Color c1, int x, int y, int width, int height, int offset)
2541
    {
2542
        DrawCorners(c1, x + offset, y + offset, width - (offset * 2), height - (offset * 2));
2543
    }
2544
2545
    protected void DrawCorners(Color c1)
2546
    {
2547
        DrawCorners(c1, 0, 0, Width, Height);
2548
    }
2549
    protected void DrawCorners(Color c1, Rectangle r1)
2550
    {
2551
        DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height);
2552
    }
2553
    protected void DrawCorners(Color c1, int x, int y, int width, int height)
2554
    {
2555
        if (_NoRounding)
2556
            return;
2557
2558
        if (_Transparent)
2559
        {
2560
            B.SetPixel(x, y, c1);
2561
            B.SetPixel(x + (width - 1), y, c1);
2562
            B.SetPixel(x, y + (height - 1), c1);
2563
            B.SetPixel(x + (width - 1), y + (height - 1), c1);
2564
        }
2565
        else
2566
        {
2567
            DrawCornersBrush = new SolidBrush(c1);
2568
            G.FillRectangle(DrawCornersBrush, x, y, 1, 1);
2569
            G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1);
2570
            G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1);
2571
            G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1);
2572
        }
2573
    }
2574
2575
    #endregion
2576
2577
    #region " DrawBorders "
2578
2579
    protected void DrawBorders(Pen p1, int offset)
2580
    {
2581
        DrawBorders(p1, 0, 0, Width, Height, offset);
2582
    }
2583
    protected void DrawBorders(Pen p1, Rectangle r, int offset)
2584
    {
2585
        DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset);
2586
    }
2587
    protected void DrawBorders(Pen p1, int x, int y, int width, int height, int offset)
2588
    {
2589
        DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2));
2590
    }
2591
2592
    protected void DrawBorders(Pen p1)
2593
    {
2594
        DrawBorders(p1, 0, 0, Width, Height);
2595
    }
2596
    protected void DrawBorders(Pen p1, Rectangle r)
2597
    {
2598
        DrawBorders(p1, r.X, r.Y, r.Width, r.Height);
2599
    }
2600
    protected void DrawBorders(Pen p1, int x, int y, int width, int height)
2601
    {
2602
        G.DrawRectangle(p1, x, y, width - 1, height - 1);
2603
    }
2604
2605
    #endregion
2606
2607
    #region " DrawText "
2608
2609
    private Point DrawTextPoint;
2610
2611
    private Size DrawTextSize;
2612
    protected void DrawText(Brush b1, HorizontalAlignment a, int x, int y)
2613
    {
2614
        DrawText(b1, Text, a, x, y);
2615
    }
2616
    protected void DrawText(Brush b1, string text, HorizontalAlignment a, int x, int y)
2617
    {
2618
        if (text.Length == 0)
2619
            return;
2620
2621
        DrawTextSize = Measure(text);
2622
        DrawTextPoint = Center(DrawTextSize);
2623
2624
        switch (a)
2625
        {
2626
            case HorizontalAlignment.Left:
2627
                G.DrawString(text, Font, b1, x, DrawTextPoint.Y + y);
2628
                break;
2629
            case HorizontalAlignment.Center:
2630
                G.DrawString(text, Font, b1, DrawTextPoint.X + x, DrawTextPoint.Y + y);
2631
                break;
2632
            case HorizontalAlignment.Right:
2633
                G.DrawString(text, Font, b1, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y);
2634
                break;
2635
        }
2636
    }
2637
2638
    protected void DrawText(Brush b1, Point p1)
2639
    {
2640
        if (Text.Length == 0)
2641
            return;
2642
        G.DrawString(Text, Font, b1, p1);
2643
    }
2644
    protected void DrawText(Brush b1, int x, int y)
2645
    {
2646
        if (Text.Length == 0)
2647
            return;
2648
        G.DrawString(Text, Font, b1, x, y);
2649
    }
2650
2651
    #endregion
2652
2653
    #region " DrawImage "
2654
2655
2656
    private Point DrawImagePoint;
2657
    protected void DrawImage(HorizontalAlignment a, int x, int y)
2658
    {
2659
        DrawImage(_Image, a, x, y);
2660
    }
2661
    protected void DrawImage(Image image, HorizontalAlignment a, int x, int y)
2662
    {
2663
        if (image == null)
2664
            return;
2665
        DrawImagePoint = Center(image.Size);
2666
2667
        switch (a)
2668
        {
2669
            case HorizontalAlignment.Left:
2670
                G.DrawImage(image, x, DrawImagePoint.Y + y, image.Width, image.Height);
2671
                break;
2672
            case HorizontalAlignment.Center:
2673
                G.DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y, image.Width, image.Height);
2674
                break;
2675
            case HorizontalAlignment.Right:
2676
                G.DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y, image.Width, image.Height);
2677
                break;
2678
        }
2679
    }
2680
2681
    protected void DrawImage(Point p1)
2682
    {
2683
        DrawImage(_Image, p1.X, p1.Y);
2684
    }
2685
    protected void DrawImage(int x, int y)
2686
    {
2687
        DrawImage(_Image, x, y);
2688
    }
2689
2690
    protected void DrawImage(Image image, Point p1)
2691
    {
2692
        DrawImage(image, p1.X, p1.Y);
2693
    }
2694
    protected void DrawImage(Image image, int x, int y)
2695
    {
2696
        if (image == null)
2697
            return;
2698
        G.DrawImage(image, x, y, image.Width, image.Height);
2699
    }
2700
2701
    #endregion
2702
2703
    #region " DrawGradient "
2704
2705
    private LinearGradientBrush DrawGradientBrush;
2706
2707
    private Rectangle DrawGradientRectangle;
2708
    protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height)
2709
    {
2710
        DrawGradientRectangle = new Rectangle(x, y, width, height);
2711
        DrawGradient(blend, DrawGradientRectangle);
2712
    }
2713
    protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height, float angle)
2714
    {
2715
        DrawGradientRectangle = new Rectangle(x, y, width, height);
2716
        DrawGradient(blend, DrawGradientRectangle, angle);
2717
    }
2718
2719
    protected void DrawGradient(ColorBlend blend, Rectangle r)
2720
    {
2721
        DrawGradientBrush = new LinearGradientBrush(r, Color.Empty, Color.Empty, 90f);
2722
        DrawGradientBrush.InterpolationColors = blend;
2723
        G.FillRectangle(DrawGradientBrush, r);
2724
    }
2725
    protected void DrawGradient(ColorBlend blend, Rectangle r, float angle)
2726
    {
2727
        DrawGradientBrush = new LinearGradientBrush(r, Color.Empty, Color.Empty, angle);
2728
        DrawGradientBrush.InterpolationColors = blend;
2729
        G.FillRectangle(DrawGradientBrush, r);
2730
    }
2731
2732
2733
    protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height)
2734
    {
2735
        DrawGradientRectangle = new Rectangle(x, y, width, height);
2736
        DrawGradient(c1, c2, DrawGradientRectangle);
2737
    }
2738
    protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height, float angle)
2739
    {
2740
        DrawGradientRectangle = new Rectangle(x, y, width, height);
2741
        DrawGradient(c1, c2, DrawGradientRectangle, angle);
2742
    }
2743
2744
    protected void DrawGradient(Color c1, Color c2, Rectangle r)
2745
    {
2746
        DrawGradientBrush = new LinearGradientBrush(r, c1, c2, 90f);
2747
        G.FillRectangle(DrawGradientBrush, r);
2748
    }
2749
    protected void DrawGradient(Color c1, Color c2, Rectangle r, float angle)
2750
    {
2751
        DrawGradientBrush = new LinearGradientBrush(r, c1, c2, angle);
2752
        G.FillRectangle(DrawGradientBrush, r);
2753
    }
2754
2755
    #endregion
2756
2757
    #region " DrawRadial "
2758
2759
    private GraphicsPath DrawRadialPath;
2760
    private PathGradientBrush DrawRadialBrush1;
2761
    private LinearGradientBrush DrawRadialBrush2;
2762
2763
    private Rectangle DrawRadialRectangle;
2764
    public void DrawRadial(ColorBlend blend, int x, int y, int width, int height)
2765
    {
2766
        DrawRadialRectangle = new Rectangle(x, y, width, height);
2767
        DrawRadial(blend, DrawRadialRectangle, width / 2, height / 2);
2768
    }
2769
    public void DrawRadial(ColorBlend blend, int x, int y, int width, int height, Point center)
2770
    {
2771
        DrawRadialRectangle = new Rectangle(x, y, width, height);
2772
        DrawRadial(blend, DrawRadialRectangle, center.X, center.Y);
2773
    }
2774
    public void DrawRadial(ColorBlend blend, int x, int y, int width, int height, int cx, int cy)
2775
    {
2776
        DrawRadialRectangle = new Rectangle(x, y, width, height);
2777
        DrawRadial(blend, DrawRadialRectangle, cx, cy);
2778
    }
2779
2780
    public void DrawRadial(ColorBlend blend, Rectangle r)
2781
    {
2782
        DrawRadial(blend, r, r.Width / 2, r.Height / 2);
2783
    }
2784
    public void DrawRadial(ColorBlend blend, Rectangle r, Point center)
2785
    {
2786
        DrawRadial(blend, r, center.X, center.Y);
2787
    }
2788
    public void DrawRadial(ColorBlend blend, Rectangle r, int cx, int cy)
2789
    {
2790
        DrawRadialPath.Reset();
2791
        DrawRadialPath.AddEllipse(r.X, r.Y, r.Width - 1, r.Height - 1);
2792
2793
        DrawRadialBrush1 = new PathGradientBrush(DrawRadialPath);
2794
        DrawRadialBrush1.CenterPoint = new Point(r.X + cx, r.Y + cy);
2795
        DrawRadialBrush1.InterpolationColors = blend;
2796
2797
        if (G.SmoothingMode == SmoothingMode.AntiAlias)
2798
        {
2799
            G.FillEllipse(DrawRadialBrush1, r.X + 1, r.Y + 1, r.Width - 3, r.Height - 3);
2800
        }
2801
        else
2802
        {
2803
            G.FillEllipse(DrawRadialBrush1, r);
2804
        }
2805
    }
2806
2807
2808
    protected void DrawRadial(Color c1, Color c2, int x, int y, int width, int height)
2809
    {
2810
        DrawRadialRectangle = new Rectangle(x, y, width, height);
2811
        DrawRadial(c1, c2, DrawRadialRectangle);
2812
    }
2813
    protected void DrawRadial(Color c1, Color c2, int x, int y, int width, int height, float angle)
2814
    {
2815
        DrawRadialRectangle = new Rectangle(x, y, width, height);
2816
        DrawRadial(c1, c2, DrawRadialRectangle, angle);
2817
    }
2818
2819
    protected void DrawRadial(Color c1, Color c2, Rectangle r)
2820
    {
2821
        DrawRadialBrush2 = new LinearGradientBrush(r, c1, c2, 90f);
2822
        G.FillEllipse(DrawRadialBrush2, r);
2823
    }
2824
    protected void DrawRadial(Color c1, Color c2, Rectangle r, float angle)
2825
    {
2826
        DrawRadialBrush2 = new LinearGradientBrush(r, c1, c2, angle);
2827
        G.FillEllipse(DrawRadialBrush2, r);
2828
    }
2829
2830
    #endregion
2831
2832
    #region " CreateRound "
2833
2834
    private GraphicsPath CreateRoundPath;
2835
2836
    private Rectangle CreateRoundRectangle;
2837
    public GraphicsPath CreateRound(int x, int y, int width, int height, int slope)
2838
    {
2839
        CreateRoundRectangle = new Rectangle(x, y, width, height);
2840
        return CreateRound(CreateRoundRectangle, slope);
2841
    }
2842
2843
    public GraphicsPath CreateRound(Rectangle r, int slope)
2844
    {
2845
        CreateRoundPath = new GraphicsPath(FillMode.Winding);
2846
        CreateRoundPath.AddArc(r.X, r.Y, slope, slope, 180f, 90f);
2847
        CreateRoundPath.AddArc(r.Right - slope, r.Y, slope, slope, 270f, 90f);
2848
        CreateRoundPath.AddArc(r.Right - slope, r.Bottom - slope, slope, slope, 0f, 90f);
2849
        CreateRoundPath.AddArc(r.X, r.Bottom - slope, slope, slope, 90f, 90f);
2850
        CreateRoundPath.CloseFigure();
2851
        return CreateRoundPath;
2852
    }
2853
2854
    #endregion
2855
2856
}
2857
2858
static class ThemeShare
2859
{
2860
2861
    #region " Animation "
2862
2863
    private static int Frames;
2864
    private static bool Invalidate;
2865
2866
    public static PrecisionTimer ThemeTimer = new PrecisionTimer();
2867
    //1000 / 50 = 20 FPS
2868
    private const int FPS = 50;
2869
2870
    private const int Rate = 10;
2871
    public delegate void AnimationDelegate(bool invalidate);
2872
2873
2874
    private static List<AnimationDelegate> Callbacks = new List<AnimationDelegate>();
2875
    private static void HandleCallbacks(IntPtr state, bool reserve)
2876
    {
2877
        Invalidate = (Frames >= FPS);
2878
        if (Invalidate)
2879
            Frames = 0;
2880
2881
        lock (Callbacks)
2882
        {
2883
            for (int I = 0; I <= Callbacks.Count - 1; I++)
2884
            {
2885
                Callbacks[I].Invoke(Invalidate);
2886
            }
2887
        }
2888
2889
        Frames += Rate;
2890
    }
2891
2892
    private static void InvalidateThemeTimer()
2893
    {
2894
        if (Callbacks.Count == 0)
2895
        {
2896
            ThemeTimer.Delete();
2897
        }
2898
        else
2899
        {
2900
            ThemeTimer.Create(0, Rate, HandleCallbacks);
2901
        }
2902
    }
2903
2904
    public static void AddAnimationCallback(AnimationDelegate callback)
2905
    {
2906
        lock (Callbacks)
2907
        {
2908
            if (Callbacks.Contains(callback))
2909
                return;
2910
2911
            Callbacks.Add(callback);
2912
            InvalidateThemeTimer();
2913
        }
2914
    }
2915
2916
    public static void RemoveAnimationCallback(AnimationDelegate callback)
2917
    {
2918
        lock (Callbacks)
2919
        {
2920
            if (!Callbacks.Contains(callback))
2921
                return;
2922
2923
            Callbacks.Remove(callback);
2924
            InvalidateThemeTimer();
2925
        }
2926
    }
2927
2928
    #endregion
2929
2930
}
2931
2932
enum MouseState : byte
2933
{
2934
    None = 0,
2935
    Over = 1,
2936
    Down = 2,
2937
    Block = 3
2938
}
2939
2940
struct Bloom
2941
{
2942
2943
    public string _Name;
2944
    public string Name
2945
    {
2946
        get { return _Name; }
2947
    }
2948
2949
    private Color _Value;
2950
    public Color Value
2951
    {
2952
        get { return _Value; }
2953
        set { _Value = value; }
2954
    }
2955
2956
    public string ValueHex
2957
    {
2958
        get { return string.Concat("#", _Value.R.ToString("X2", null), _Value.G.ToString("X2", null), _Value.B.ToString("X2", null)); }
2959
        set
2960
        {
2961
            try
2962
            {
2963
                _Value = ColorTranslator.FromHtml(value);
2964
            }
2965
            catch
2966
            {
2967
                return;
2968
            }
2969
        }
2970
    }
2971
2972
2973
    public Bloom(string name, Color value)
2974
    {
2975
        _Name = name;
2976
        _Value = value;
2977
    }
2978
}
2979
2980
//------------------
2981
//Creator: aeonhack
2982
//Site: elitevs.net
2983
//Created: 11/30/2011
2984
//Changed: 11/30/2011
2985
//Version: 1.0.0
2986
//------------------
2987
class PrecisionTimer : IDisposable
2988
{
2989
2990
    private bool _Enabled;
2991
    public bool Enabled
2992
    {
2993
        get { return _Enabled; }
2994
    }
2995
2996
    private IntPtr Handle;
2997
2998
    private TimerDelegate TimerCallback;
2999
    [DllImport("kernel32.dll", EntryPoint = "CreateTimerQueueTimer")]
3000
    private static extern bool CreateTimerQueueTimer(ref IntPtr handle, IntPtr queue, TimerDelegate callback, IntPtr state, uint dueTime, uint period, uint flags);
3001
3002
    [DllImport("kernel32.dll", EntryPoint = "DeleteTimerQueueTimer")]
3003
    private static extern bool DeleteTimerQueueTimer(IntPtr queue, IntPtr handle, IntPtr callback);
3004
3005
    public delegate void TimerDelegate(IntPtr r1, bool r2);
3006
3007
    public void Create(uint dueTime, uint period, TimerDelegate callback)
3008
    {
3009
        if (_Enabled)
3010
            return;
3011
3012
        TimerCallback = callback;
3013
        bool Success = CreateTimerQueueTimer(ref Handle, IntPtr.Zero, TimerCallback, IntPtr.Zero, dueTime, period, 0);
3014
3015
        if (!Success)
3016
            ThrowNewException("CreateTimerQueueTimer");
3017
        _Enabled = Success;
3018
    }
3019
3020
    public void Delete()
3021
    {
3022
        if (!_Enabled)
3023
            return;
3024
        bool Success = DeleteTimerQueueTimer(IntPtr.Zero, Handle, IntPtr.Zero);
3025
3026
        if (!Success && !(Marshal.GetLastWin32Error() == 997))
3027
        {
3028
            ThrowNewException("DeleteTimerQueueTimer");
3029
        }
3030
3031
        _Enabled = !Success;
3032
    }
3033
3034
    private void ThrowNewException(string name)
3035
    {
3036
        throw new Exception(string.Format("{0} failed. Win32Error: {1}", name, Marshal.GetLastWin32Error()));
3037
    }
3038
3039
    public void Dispose()
3040
    {
3041
        Delete();
3042
    }
3043
}
3044
3045
#endregion