-
Notifications
You must be signed in to change notification settings - Fork 12
/
ParameterField.cs
63 lines (53 loc) · 1.56 KB
/
ParameterField.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
using System;
using System.Windows.Forms;
public class ParameterField
{
public enum Type
{
BOOLEAN = 0,
LIST = 1,
NUMBER = 2,
INVALID = 3
};
private Control control;
private String description;
private byte offset, length;
private Type type;
//type specific variables
private String[] possibleValues;
private float start;
private float step;
private float end;
public ParameterField(Type type, object[] values, ushort[] hexValues, byte dataOffset, byte dataLength, String description = "No Description provided." )
{
this.description = description;
this.offset = dataOffset;
this.length = dataLength;
if (type = Type.NUMBER)
{
try
{
this.start = (Decimal)values[0];
this.step = (Decimal)values[1];
this.end = (Decimal)values[2];
} catch(Exception e)
{
this.type = Type.INVALID;
}
} else if (type = Type.LIST)
{
this.possibleValues = new String[values.Length];
for (int i = 0; i<values.Length; i++)
{
this.possibleValues[i] = values[i].ToString();
}
}
}
public Control CreateControl(EventHandler eventHandler)
{
System.Windows.Forms.NumericUpDown numericUpDown = new System.Windows.Forms.NumericUpDown();
numericUpDown.ValueChanged += eventHandler;
this.control = numericUpDown;
return control;
}
}