-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathFlagControl.cs
83 lines (71 loc) · 2.27 KB
/
FlagControl.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
using System;
using System.Windows.Forms;
namespace Material_Editor
{
public partial class FlagControl : CustomControl
{
private Label lbLabel;
private CheckedListBox checkedList;
public FlagControl(string label, Func<CustomControl, bool> visibilityCallback, Action<CustomControl> changedCallback, object[] entries, int flagValue) : base(label)
{
lbLabel.Text = label;
checkedList.Items.AddRange(entries);
for (int i = 0; i < checkedList.Items.Count; i++)
{
if ((flagValue & (1 << i)) != 0)
{
checkedList.SetItemChecked(i, true);
}
}
VisibilityCallback = visibilityCallback;
ChangedCallback = changedCallback;
}
public override void CreateControls()
{
lbLabel = new Label
{
Anchor = AnchorStyles.Top | AnchorStyles.Left,
AutoSize = true,
Name = "lbLabel",
TabIndex = 0,
Text = "Label",
Tag = this
};
checkedList = new CheckedListBox
{
Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
ColumnWidth = 150,
FormattingEnabled = true,
MultiColumn = true,
Name = "checkedList",
TabIndex = 1,
Tag = this
};
checkedList.SelectedIndexChanged += new EventHandler(CheckedList_SelectedIndexChanged);
}
public override Label LabelControl
{
get { return lbLabel; }
}
public override Control Control
{
get { return checkedList; }
}
public override object GetProperty()
{
int flagValue = 0;
for (int i = 0; i < checkedList.Items.Count; i++)
{
if (checkedList.GetItemChecked(i))
{
flagValue |= 1 << i;
}
}
return flagValue;
}
private void CheckedList_SelectedIndexChanged(object sender, EventArgs e)
{
InvokeChangedCallback();
}
}
}