-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryIntegerEntryControl.cs
More file actions
234 lines (216 loc) · 8.42 KB
/
BinaryIntegerEntryControl.cs
File metadata and controls
234 lines (216 loc) · 8.42 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using VisualBinaryEditor.BinaryEntries;
namespace VisualBinaryEditor
{
internal class BinaryIntegerEntryControl : IBinaryEntryControl
{
internal static IBinaryEntryControl CreateByte(in int index, in Panel parent)
{
return new BinaryIntegerEntryControl(index, parent, new BinaryByteEntry());
}
internal static IBinaryEntryControl CreateSbyte(in int index, in Panel parent)
{
return new BinaryIntegerEntryControl(index, parent, new BinarySbyteEntry());
}
internal static IBinaryEntryControl CreateShort(in int index, in Panel parent)
{
return new BinaryIntegerEntryControl(index, parent, new BinaryShortEntry());
}
internal static IBinaryEntryControl CreateUshort(in int index, in Panel parent)
{
return new BinaryIntegerEntryControl(index, parent, new BinaryUshortEntry());
}
internal static IBinaryEntryControl CreateInt(in int index, in Panel parent)
{
return new BinaryIntegerEntryControl(index, parent, new BinaryIntEntry());
}
internal static IBinaryEntryControl CreateUint(in int index, in Panel parent)
{
return new BinaryIntegerEntryControl(index, parent, new BinaryUintEntry());
}
internal static IBinaryEntryControl CreateLong(in int index, in Panel parent)
{
return new BinaryIntegerEntryControl(index, parent, new BinaryLongEntry());
}
internal static IBinaryEntryControl CreateUlong(in int index, in Panel parent)
{
return new BinaryIntegerEntryControl(index, parent, new BinaryUlongEntry());
}
private readonly Panel _parentPanel;
private readonly BinaryIntegerEntryBase binaryEntry;
private readonly Panel panel;
private readonly Label indexLabel;
private readonly Label nameLabel;
private readonly TextBox nameTextBox;
private readonly Label typeLabel;
private readonly Label valueLabel;
private readonly NumericUpDown valueBox;
// private readonly TextBox valueTextBox;
private int _index;
public int Index
{
get
{
return _index;
}
set
{
_index = value;
panel.Location = BinaryEntryControlCreater.GetLocation(_index, _parentPanel.AutoScrollPosition);
indexLabel.Text = BinaryEntryControlCreater.GetIndexText(_index);
}
}
private bool _selected;
public bool Selected
{
get
{
return _selected;
}
set
{
_selected = value;
Color panelColor = _selected ? SystemColors.Highlight : SystemColors.ControlLightLight;
Color textColor = _selected ? SystemColors.HighlightText : SystemColors.ControlText;
panel.BackColor = panelColor;
indexLabel.ForeColor = textColor;
nameLabel.ForeColor = textColor;
typeLabel.ForeColor = textColor;
valueLabel.ForeColor = textColor;
nameTextBox.Enabled = _selected;
valueBox.Enabled = _selected;
if (!_selected)
{
return;
}
valueBox.Focus();
}
}
public Control Control => panel;
public event EventHandler? Click
{
add
{
panel.Click += value;
indexLabel.Click += value;
nameLabel.Click += value;
typeLabel.Click += value;
valueLabel.Click += value;
}
remove
{
panel.Click -= value;
indexLabel.Click -= value;
nameLabel.Click -= value;
typeLabel.Click -= value;
valueLabel.Click -= value;
}
}
private BinaryIntegerEntryControl(in int index, in Panel parent, in BinaryIntegerEntryBase entry)
{
_index = index;
_parentPanel = parent;
binaryEntry = entry;
panel = new Panel();
indexLabel = new Label();
nameLabel = new Label();
nameTextBox = new TextBox();
typeLabel = new Label();
valueLabel = new Label();
valueBox = new NumericUpDown();
panel.SuspendLayout();
((ISupportInitialize)valueBox).BeginInit();
parent.Controls.Add(panel);
panel.BackColor = SystemColors.ControlLightLight;
panel.Controls.Add(indexLabel);
panel.Controls.Add(nameLabel);
panel.Controls.Add(nameTextBox);
panel.Controls.Add(typeLabel);
panel.Controls.Add(valueLabel);
panel.Controls.Add(valueBox);
panel.Location = BinaryEntryControlCreater.GetLocation(index, _parentPanel.AutoScrollPosition);
panel.Name = "binaryNumberEntryPanel";
panel.Size = BinaryEntryControlCreater.PanelSize;
indexLabel.SetAsIndexLabel(index);
nameLabel.SetAsNameLabel();
nameTextBox.SetAsNameTextBox();
typeLabel.SetAsTypeLabel(binaryEntry.Type);
valueLabel.SetAsValueLabel();
valueBox.Location = new Point(460, 10);
valueBox.Name = "valueBox";
valueBox.Size = BinaryEntryControlCreater.ValueBoxSize;
valueBox.TabIndex = 20;
switch (binaryEntry.Type)
{
case BinaryType.Byte:
valueBox.Minimum = byte.MinValue;
valueBox.Maximum = byte.MaxValue;
break;
case BinaryType.Sbyte:
valueBox.Minimum = sbyte.MinValue;
valueBox.Maximum = sbyte.MaxValue;
break;
case BinaryType.Short:
valueBox.Minimum = short.MinValue;
valueBox.Maximum = short.MaxValue;
break;
case BinaryType.Ushort:
valueBox.Minimum = ushort.MinValue;
valueBox.Maximum = ushort.MaxValue;
break;
case BinaryType.Int:
valueBox.Minimum = int.MinValue;
valueBox.Maximum = int.MaxValue;
break;
case BinaryType.Uint:
valueBox.Minimum = uint.MinValue;
valueBox.Maximum = uint.MaxValue;
break;
case BinaryType.Long:
valueBox.Minimum = long.MinValue;
valueBox.Maximum = long.MaxValue;
break;
case BinaryType.Ulong:
valueBox.Minimum = ulong.MinValue;
valueBox.Maximum = ulong.MaxValue;
break;
case BinaryType.Float:
valueBox.Minimum = new decimal(float.MinValue);
valueBox.Maximum = new decimal(float.MaxValue);
valueBox.Increment = new decimal(0.1f);
break;
case BinaryType.Double:
valueBox.Minimum = new decimal(double.MinValue);
valueBox.Maximum = new decimal(double.MaxValue);
valueBox.Increment = new decimal(0.1);
break;
case BinaryType.Decimal:
valueBox.Minimum = decimal.MinValue;
valueBox.Maximum = decimal.MaxValue;
valueBox.Increment = 0.1M;
break;
}
valueBox.ValueChanged += (sender, _) =>
{
binaryEntry.SetValue(valueBox.Value);
};
valueBox.Enabled = false;
panel.ResumeLayout(false);
panel.PerformLayout();
((ISupportInitialize)valueBox).EndInit();
}
public void Read(in BinaryReader reader)
{
binaryEntry.Read(reader);
valueBox.Value = binaryEntry.GetValue();
}
public void Write(in BinaryWriter writer)
{
binaryEntry.Write(writer);
}
}
}