-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathColorControl.cs
84 lines (71 loc) · 2.28 KB
/
ColorControl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Material_Editor
{
public partial class ColorControl : CustomControl
{
private Label lbLabel;
private Button btColor;
private ColorDialog colorDialog;
public Color CurrentColor = Color.White;
public override Label LabelControl
{
get { return lbLabel; }
}
public override Control Control
{
get { return btColor; }
}
public ColorControl(string label, Func<CustomControl, bool> visibilityCallback, Action<CustomControl> changedCallback, Color initialColor) : base(label)
{
lbLabel.Text = label;
CurrentColor = initialColor;
btColor.BackColor = CurrentColor;
colorDialog.Color = CurrentColor;
VisibilityCallback = visibilityCallback;
ChangedCallback = changedCallback;
}
public override void CreateControls()
{
lbLabel = new Label
{
Anchor = AnchorStyles.Top | AnchorStyles.Left,
AutoSize = true,
Name = "lbLabel",
Text = "Label",
Tag = this
};
btColor = new Button
{
Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
BackColor = Color.White,
FlatStyle = FlatStyle.Standard,
Name = "btColor",
TabIndex = 1,
UseVisualStyleBackColor = false,
Tag = this
};
btColor.Click += new EventHandler(BtColor_Click);
colorDialog = new ColorDialog
{
FullOpen = true
};
}
private void BtColor_Click(object sender, EventArgs e)
{
var btColor = sender as Button;
colorDialog.Color = CurrentColor;
if (colorDialog.ShowDialog() == DialogResult.OK)
{
CurrentColor = colorDialog.Color;
btColor.BackColor = CurrentColor;
InvokeChangedCallback();
}
}
public override object GetProperty()
{
return btColor.BackColor;
}
}
}