-
Notifications
You must be signed in to change notification settings - Fork 12
/
CheckControl.cs
77 lines (67 loc) · 2.18 KB
/
CheckControl.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
using System;
using System.Windows.Forms;
namespace Material_Editor
{
public partial class CheckControl : CustomControl
{
private Label lbLabel;
private CheckBox check;
public override Label LabelControl
{
get { return lbLabel; }
}
public override Control Control
{
get { return check; }
}
public CheckControl(string label, Func<CustomControl, bool> visibilityCallback, Action<CustomControl> changedCallback, bool initialChecked = false) : base(label)
{
lbLabel.Text = label;
check.Checked = initialChecked;
VisibilityCallback = visibilityCallback;
ChangedCallback = changedCallback;
}
public override void CreateControls()
{
lbLabel = new Label
{
Anchor = AnchorStyles.Top | AnchorStyles.Left,
AutoSize = true,
Name = "lbLabel",
Text = "Label",
Tag = this
};
check = new CheckBox
{
Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
CheckAlign = System.Drawing.ContentAlignment.TopLeft,
TextAlign = System.Drawing.ContentAlignment.TopLeft,
Name = "check",
TabIndex = 0,
ForeColor = System.Drawing.Color.FromName("red"),
Text = "Off",
Tag = this
};
check.CheckedChanged += new EventHandler(Check_CheckedChanged);
}
private void Check_CheckedChanged(object sender, EventArgs e)
{
var check = sender as CheckBox;
if (check.Checked)
{
check.ForeColor = System.Drawing.Color.FromName("green");
check.Text = "On";
}
else
{
check.ForeColor = System.Drawing.Color.FromName("red");
check.Text = "Off";
}
InvokeChangedCallback();
}
public override object GetProperty()
{
return check.Checked;
}
}
}