-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColorPickerPreview.cs
57 lines (50 loc) · 1.48 KB
/
ColorPickerPreview.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Drawing;
using System.Windows.Forms;
namespace TrayTools {
public partial class ColorPickerPreview : UserControl {
Pen borderPen;
Brush original;
Brush current;
FloatingColor color;
public ColorPickerPreview() {
InitializeComponent();
borderPen = new Pen(System.Drawing.Color.FromArgb(113, 122, 138));
original = new SolidBrush(System.Drawing.Color.Red);
current = new SolidBrush(System.Drawing.Color.Blue);
}
public FloatingColor Color {
get {
return color;
}
set {
color = value;
if(color != null) {
current = new SolidBrush(color.ToColor());
original = new SolidBrush(color.ToColor());
color.OnChange += new FloatingColor.OnChangeEvent(color_OnChange);
}
}
}
void color_OnChange() {
current = new SolidBrush(color.ToColor());
this.Invalidate();
}
void ColorPickerPreview_Paint(object sender, PaintEventArgs e) {
Rectangle borderRect = e.ClipRectangle;
borderRect.Width--;
borderRect.Height--;
e.Graphics.DrawRectangle(borderPen, borderRect);
Rectangle rect = e.ClipRectangle;
rect.X++;
rect.Y++;
rect.Width -= 2;
rect.Height -= 2;
rect.Height /= 2;
e.Graphics.FillRectangle(current, rect);
rect.Y += rect.Height;
rect.Height = e.ClipRectangle.Height - 2 - rect.Height;
e.Graphics.FillRectangle(original, rect);
}
}
}