View difference between Paste ID: cBvgsw4w and uWJE0Ta8
SHOW: | | - or go back to the newest paste.
1
using System;
2
using System.ComponentModel;
3
using System.Drawing;
4
using System.Drawing.Drawing2D;
5
using System.Drawing.Text;
6
using System.Runtime.InteropServices;
7
using System.Windows.Forms;
8
9
/*-------------------------*/
10
//Theme:          EasyColour
11
//Creator:        Euras
12
//Version:        1.0
13
//Created:        02/08/14
14
//Website:        eurashd.com
15
/*-------------------------*/
16
17
namespace EasyColour
18
{
19
    class EC_Theme : ContainerControl
20
    {
21
        [DllImportAttribute("user32.dll")]
22
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
23
        [DllImportAttribute("user32.dll")]
24
        public static extern bool ReleaseCapture();
25
        public const int WM_NCLBUTTONDOWN = 0xA1;
26
        public const int HT_CAPTION = 0x2;
27
28
        protected override sealed void OnHandleCreated(EventArgs e)
29
        {
30
            base.Dock = DockStyle.Fill;
31
            ForeColor = Color.White;
32
            base.OnHandleCreated(e);
33
        }
34
35
        private bool _IsParentForm;
36
        protected bool IsParentForm
37
        {
38
            get { return _IsParentForm; }
39
        }
40
41
        private bool _Transparent;
42
        public bool Transparent
43
        {
44
            get { return _Transparent; }
45
            set
46
            {
47
                _Transparent = value;
48
                if (!(IsHandleCreated))
49
                    return;
50
51
                SetStyle(ControlStyles.Opaque, !value);
52
                SetStyle(ControlStyles.SupportsTransparentBackColor, value);
53
                Invalidate();
54
            }
55
        }
56
57
        protected override sealed void OnParentChanged(EventArgs e)
58
        {
59
            base.OnParentChanged(e);
60
61
            if (Parent == null)
62
                return;
63
            _IsParentForm = Parent is Form;
64
65
            if (_IsParentForm)
66
            {
67
                ParentForm.FormBorderStyle = _BorderStyle;
68
            }
69
            Parent.BackColor = BackColor;
70
        }
71
72
        private FormBorderStyle _BorderStyle;
73
        public FormBorderStyle BorderStyle
74
        {
75
            get
76
            {
77
                if (_IsParentForm)
78
                    return ParentForm.FormBorderStyle;
79
                else
80
                    return _BorderStyle;
81
            }
82
            set
83
            {
84
                _BorderStyle = value;
85
                if (_IsParentForm)
86
                {
87
                    ParentForm.FormBorderStyle = value;
88
                }
89
            }
90
        }
91
92
        protected override CreateParams CreateParams
93
        {
94
            get
95
            {
96
                const int CS_DROPSHADOW = 0x20000;
97
                CreateParams cp = base.CreateParams;
98
                cp.ClassStyle |= CS_DROPSHADOW;
99
                return cp;
100
            }
101
        }
102
103
        protected override void OnMouseDown(MouseEventArgs e)
104
        {
105
            if (e.Button == MouseButtons.Left)
106
            {
107
                ReleaseCapture();
108
                SendMessage(Parent.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
109
            }
110
            base.OnMouseDown(e);
111
        }
112
113
        protected override void OnPaint(PaintEventArgs e)
114
        {
115
            base.OnPaint(e);
116
            Graphics g = e.Graphics;
117
            g.SmoothingMode = SmoothingMode.HighQuality;
118
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
119
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
120
121
            g.FillRectangle(new SolidBrush(Color.FromArgb(75, 0, 0, 0)), new Rectangle(-1, -1, Width + 1, 25));
122
            Image icon = Properties.Resources.icon;
123
            Size iSize = new Size(16, 16);
124
            g.DrawImage(icon, 5, 5, 16, 16);
125
            g.DrawString(Text, Font, new SolidBrush(ForeColor), new Point(25, 5), StringFormat.GenericDefault);
126
127
            g.Dispose();
128
        }
129
    }
130
131
    class EC_Button : Control
132
    {
133
        bool isHover;
134
        string _ButtonText;
135
        Image _Image;
136
        Size _ImageSize;
137
138
        // Initilize Button
139
        public EC_Button()
140
        {
141
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
142
            BackColor = Color.Transparent;
143
            Cursor = Cursors.Hand;
144
        }
145
146
        // Mouse Hover Events
147
        protected override void OnMouseEnter(EventArgs e)
148
        {
149
            base.OnMouseEnter(e);
150
            isHover = true;
151
            Invalidate();
152
        }
153
154
        protected override void OnMouseLeave(EventArgs e)
155
        {
156
            base.OnMouseLeave(e);
157
            isHover = false;
158
            Invalidate();
159
        }
160
161
        // Button Text Property
162
        [Category("Appearance")]
163
        public override string Text
164
        {
165
            get { return _ButtonText; }
166
            set { _ButtonText = value; }
167
        }
168
169
        // Button Image Property
170
        [Category("Appearance")]
171
        public Image Image
172
        {
173
            get { return _Image; }
174
            set { _Image = value; }
175
        }
176
177
        // Image Size Property
178
        [Category("Appearance")]
179
        public Size ImageSize
180
        {
181
            get { return _ImageSize; }
182
            set { _ImageSize = value; }
183
        }
184
185
        protected override void OnPaint(PaintEventArgs e)
186
        {
187
            base.OnPaint(e);
188
            Graphics g = e.Graphics;
189
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
190
191
            SizeF s = g.MeasureString(_ButtonText, Font);
192
            int x = ClientSize.Width;
193
            int y = ClientSize.Height;
194
195
            // Top / Bottom Fills
196
            g.FillRectangle(new SolidBrush(Color.FromArgb(120, 0, 0, 0)), new Rectangle(0, y / 2, x - 1, y - 1));
197
            g.FillRectangle(new SolidBrush(Color.FromArgb(80, 0, 0, 0)), new Rectangle(0, 0, x - 1, y / 2));
198
199
            if (Text == null)
200
            {
201
                _ButtonText = Name;
202
            }
203
204
            // Draw Button Text
205
            g.DrawString(_ButtonText, Font, new SolidBrush(Color.White), (x - s.Width) / 2, (y - s.Height) / 2);
206
207
            // Apply Button Image
208
            if (_Image != null)
209
            {
210
                int imgX = _ImageSize.Width;
211
                int imgY = _ImageSize.Height;
212
213
                if (_ImageSize != null)
214
                {
215
                    g.DrawImage(_Image, 5, (y - imgY) / 2, imgX, imgY);
216
                }
217
                else
218
                {
219
                    g.DrawImage(_Image, 5, (y - imgY) / 2, 16, 16);
220
                }
221
            }
222
223
            // Button Hover Overlay
224
            if (isHover)
225
            {
226
                g.FillRectangle(new SolidBrush(Color.FromArgb(25, 0, 0, 0)), new Rectangle(0, 0, x, y));
227
            }
228
229
            g.Dispose();
230
        }
231
    }
232
233
    class EC_CheckBox : Control
234
    {
235
        bool _Checked;
236
237
        // Initialize Checkbox
238
        public EC_CheckBox()
239
        {
240
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
241
            BackColor = Color.Transparent;
242
            Size = new Size(20, 20);
243
            MaximumSize = Size;
244
            MinimumSize = Size;
245
            Cursor = Cursors.Hand;
246
        }
247
248
        // "Check" Events
249
        protected override void OnMouseClick(MouseEventArgs e)
250
        {
251
            if (_Checked)
252
            {
253
                _Checked = false;
254
            }
255
            else if (!_Checked)
256
            {
257
                _Checked = true;
258
            }
259
            Invalidate();
260
            base.OnMouseClick(e);
261
        }
262
263
        public bool Checked
264
        {
265
            get { return _Checked; }
266
            set { _Checked = value; }
267
        }
268
269
        protected override void OnPaint(PaintEventArgs e)
270
        {
271
            base.OnPaint(e);
272
            Graphics g = e.Graphics;
273
            g.SmoothingMode = SmoothingMode.HighQuality;
274
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
275
            int x = ClientSize.Width;
276
            int y = ClientSize.Height;
277
278
            // Fill Outer / Inner Box
279
            g.FillEllipse(new SolidBrush(Color.FromArgb(25, 0, 0, 0)), new Rectangle(0, 0, x - 1, y - 1));
280
            g.FillEllipse(new SolidBrush(Color.FromArgb(75, 255, 255, 255)), new Rectangle(3, 3, x - 7, y - 7));
281
282
            // Apply Check Overlay
283
            if (_Checked)
284
            {
285
                g.FillEllipse(new SolidBrush(Color.FromArgb(100, 0, 0, 0)), new RectangleF(5, 5, (x / 2) - 1, (y / 2) - 1));
286
            }
287
288
            g.Dispose();
289
        }
290
    }
291
292
    class EC_Panel : Panel
293
    {
294
        public string _PanelText;
295
296
        // Text To Display On Panel
297
        [Category("Appearance")]
298
        public string PanelText
299
        {
300
            get { return _PanelText; }
301
            set { _PanelText = value; }
302
        }
303
304
        protected override void OnPaint(PaintEventArgs e)
305
        {
306
            base.OnPaint(e);
307
            Graphics g = e.Graphics;
308
            g.SmoothingMode = SmoothingMode.HighQuality;
309
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
310
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
311
            int x = ClientSize.Width;
312
            int y = ClientSize.Height;
313
314
            // Top Bar Fill
315
            g.FillRectangle(new SolidBrush(Color.FromArgb(25, 0, 0, 0)), new Rectangle(0, 0, x, 25));
316
317
            if (PanelText == null)
318
            {
319
                _PanelText = Name;
320
            }
321
322
            // Main Fill & Draw Text
323
            g.FillRectangle(new SolidBrush(Color.FromArgb(50, 0, 0, 0)), new Rectangle(0, 0, x, y));
324
            g.DrawString(_PanelText, Font, new SolidBrush(Color.White), new Point(5, 5));
325
326
            g.Dispose();
327
        }
328
    }
329
330
    class EC_Tabs : TabControl
331
    {
332
        // Initialize
333
        public EC_Tabs()
334
        {
335
            DrawMode = TabDrawMode.OwnerDrawFixed;
336
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
337
            DoubleBuffered = true;
338
            Dock = DockStyle.Bottom;
339
            SizeMode = TabSizeMode.Normal;
340
            ItemSize = new Size(100, 20);
341
        }
342
343
        // Tabs Back Color Property
344
        private Color m_Backcolor = Color.Empty;
345
        [Browsable(true)]
346
        public override Color BackColor
347
        {
348
            get
349
            {
350
                if (m_Backcolor.Equals(Color.Empty))
351
                {
352
                    if (Parent == null)
353
                        return Control.DefaultBackColor;
354
                    else
355
                        return Parent.BackColor;
356
                }
357
                return m_Backcolor;
358
            }
359
            set
360
            {
361
                if (m_Backcolor.Equals(value)) return;
362
                m_Backcolor = value;
363
                Invalidate();
364
                base.OnBackColorChanged(EventArgs.Empty);
365
            }
366
        }
367
368
        public bool ShouldSerializeBackColor()
369
        {
370
            return !m_Backcolor.Equals(Color.Empty);
371
        }
372
373
        public override void ResetBackColor()
374
        {
375
            m_Backcolor = Color.Empty;
376
            Invalidate();
377
        }
378
379
        protected override void OnPaint(PaintEventArgs e)
380
        {
381
            base.OnPaint(e);
382
            Graphics g = e.Graphics;
383
            g.Clear(BackColor);
384
385
            g.SmoothingMode = SmoothingMode.HighQuality;
386
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
387
388
            // Apply Colouring To Each Tab Page
389
            for (int i = 0; i <= TabPages.Count - 1; i++)
390
            {
391
                Rectangle rect = GetTabRect(i);
392
                Rectangle r = new Rectangle(GetTabRect(i).X + 10, GetTabRect(i).Y + 3, 100, 20);
393
                if (SelectedTab == TabPages[i])
394
                {
395
                    g.FillRectangle(new SolidBrush(Color.FromArgb(75, 0, 0, 0)), rect);
396
                }
397
                else
398
                {
399
                    g.FillRectangle(new SolidBrush(Color.FromArgb(25, 0, 0, 0)), rect);
400
                }
401
402
                // Draw Tab Page Text
403
                g.DrawString(TabPages[i].Text, Font, new SolidBrush(Color.White), (Rectangle)r);
404
                TabPages[i].UseVisualStyleBackColor = false;
405
            }
406
        }
407
    }
408
409
    class EC_Notification : UserControl
410
    {
411
        string _Text;
412
413
        // Initialize
414
        public EC_Notification()
415
        {
416
            SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
417
            DoubleBuffered = true;
418
            BackColor = Color.Transparent;
419
            Size = new Size(200, 25);
420
        }
421
422
        // Notification Property
423
        [Category("Appearance")]
424
        public string Notification
425
        {
426
            get { return _Text; }
427
            set { _Text = value; }
428
        }
429
430
        protected override void OnPaint(PaintEventArgs e)
431
        {
432
            base.OnPaint(e);
433
            Graphics g = e.Graphics;
434
435
            SizeF s = g.MeasureString(_Text, Font);
436
            g.SmoothingMode = SmoothingMode.HighQuality;
437
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
438
            int x = ClientSize.Width;
439
            int y = ClientSize.Height;
440
441
            // Notification Shadow
442
            g.FillRectangle(new SolidBrush(Color.FromArgb(35, Color.Black)), new Rectangle(5, 5, x, y));
443
            // Notification Fill
444
            g.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, x - 5, y - 5));
445
            // Notification Text
446
            g.DrawString(_Text, Font, new SolidBrush(Color.Black), new PointF(5, ((y - 5) - s.Height) / 2));
447
        }
448
    }
449
450
    class EC_ProgressBar : Control
451
    {
452
        int max = 100;
453
        int min = 0;
454
        int val = 0;
455
456
        // Initialize
457
        public EC_ProgressBar()
458
        {
459
            base.Size = new Size(150, 15);
460
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
461
            BackColor = Color.FromArgb(25, 0, 0, 0);
462
            ForeColor = Color.FromArgb(200, 255, 255, 255);
463
        }
464
465
        // Progress Bar Minimum Value
466
        public int Min
467
        {
468
            get { return min; }
469
            set
470
            {
471
                if (value < 0)
472
                {
473
                    min = 0;
474
                }
475
                if (value > max)
476
                {
477
                    min = value;
478
                    min = value;
479
                }
480
                if (value < min)
481
                {
482
                    value = min;
483
                }
484
                Invalidate();
485
            }
486
        }
487
488
        // Progress Bar Maximum Value
489
        public int Max
490
        {
491
            get { return max; }
492
            set
493
            {
494
                if (value < min)
495
                {
496
                    min = value;
497
                }
498
                max = value;
499
                if (value > max)
500
                {
501
                    value = max;
502
                }
503
                Invalidate();
504
            }
505
        }
506
507
        // Progress Bar Current Value
508
        public int Value
509
        {
510
            get { return val; }
511
            set
512
            {
513
                int oldValue = val;
514
                if (value < min)
515
                {
516
                    val = min;
517
                }
518
                else if (value > max)
519
                {
520
                    val = max;
521
                }
522
                else
523
                {
524
                    val = value;
525
                }
526
527
                float percent;
528
529
                Rectangle newValueRect = new Rectangle(ClientRectangle.X + 2, ClientRectangle.Y + 2, 
530
                    ClientRectangle.Width - 4, ClientRectangle.Height - 4);
531
                Rectangle oldValueRect = new Rectangle(ClientRectangle.X + 2, ClientRectangle.Y + 2, 
532
                    ClientRectangle.Width - 4, ClientRectangle.Height - 4);
533
534
                percent = (float)(val - min) / (float)(max - min);
535
                newValueRect.Width = (int)((float)newValueRect.Width * percent);
536
537
                percent = (float)(oldValue - min) / (float)(max - min);
538
                oldValueRect.Width = (int)((float)oldValueRect.Width * percent);
539
540
                Rectangle updateRect = new Rectangle();
541
542
                if (newValueRect.Width > oldValueRect.Width)
543
                {
544
                    updateRect.X = oldValueRect.Size.Width;
545
                    updateRect.Width = newValueRect.Width - oldValueRect.Width;
546
                }
547
                else
548
                {
549
                    updateRect.X = newValueRect.Size.Width;
550
                    updateRect.Width = oldValueRect.Width - newValueRect.Width;
551
                }
552
553
                updateRect.Height = Height;
554
                Invalidate(updateRect);
555
            }
556
        }
557
558
        protected override void OnPaintBackground(PaintEventArgs pevent)
559
        {
560
            base.OnPaintBackground(pevent);
561
            Graphics g = pevent.Graphics;
562
            // Progress Bar Background Colour
563
            g.FillRectangle(new SolidBrush(BackColor), new Rectangle(0, 0, Width, Height));
564
        }
565
566
        protected override void OnPaint(PaintEventArgs e)
567
        {
568
            base.OnPaint(e);
569
            Graphics g = e.Graphics;
570
            SolidBrush brush = new SolidBrush(ForeColor);
571
            float percent = (float)(val - min) / (float)(max - min);
572
            Rectangle rect = new Rectangle(2, 2, Width - 4, Height - 4);
573
            rect.Width = (int)((float)rect.Width * percent);
574
            
575
            // Progress Bar ForeColour
576
            g.FillRectangle(brush, rect);
577
        }
578
    }
579
580
    class EC_TextBox : RichTextBox
581
    {
582
        // Initialize
583
        public EC_TextBox()
584
        {
585
            BorderStyle = BorderStyle.None;
586
            Multiline = false;
587
            Size = new Size(Size.Width, 20);
588
            MaximumSize = new Size(int.MaxValue, Size.Height);
589
            MinimumSize = Size;
590
        }
591
592
        // PREVENT FLICKERING
593
        protected override void OnPaintBackground(PaintEventArgs pevent)
594
        {
595
            base.OnPaintBackground(pevent);
596
        }
597
598
        private const int WM_PAINT = 15;
599
        protected override void WndProc(ref Message m)
600
        {
601
            if (m.Msg == WM_PAINT)
602
            {
603
                Invalidate();
604
                base.WndProc(ref m);
605
                using (Graphics g = Graphics.FromHwnd(Handle))
606
                {
607
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
608
                }
609
            }
610
            else
611
            {
612
                base.WndProc(ref m);
613
            }
614
        }
615
    }
616
}