-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHexNumericUpdown.cs
More file actions
47 lines (45 loc) · 1.18 KB
/
HexNumericUpdown.cs
File metadata and controls
47 lines (45 loc) · 1.18 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
using System;
using System.ComponentModel;
using System.Windows.Forms;
public class HexNumericUpdown : NumericUpDown
{
public HexNumericUpdown()
{
base.Hexadecimal = true;
base.Minimum = 0;
base.Maximum = uint.MaxValue;
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new decimal Maximum
{ // Doesn't serialize properly
get { return base.Maximum; }
set { base.Maximum = value; }
}
protected override void UpdateEditText()
{
if (base.UserEdit) HexParseEditText();
if (!string.IsNullOrEmpty(base.Text))
{
base.ChangingText = true;
base.Text = string.Format("{0:X}", (uint)base.Value);
}
}
protected override void ValidateEditText()
{
HexParseEditText();
UpdateEditText();
}
private void HexParseEditText()
{
try
{
if (!string.IsNullOrEmpty(base.Text))
this.Value = Convert.ToInt64(base.Text, 16);
}
catch { }
finally
{
base.UserEdit = false;
}
}
}