forked from jaysonragasa/MultiRDPClient.NET
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEditors.cs
More file actions
95 lines (92 loc) · 1.7 KB
/
Editors.cs
File metadata and controls
95 lines (92 loc) · 1.7 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
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace CommonTools
{
public abstract class BaseEditor<T> : TextBox
{
protected string m_filterString = string.Empty;
protected T m_lastValue;
protected virtual bool IsValidChar(char ch)
{
if (m_filterString.Length == 0 || m_filterString.IndexOf(ch) >= 0)
return true;
return false;
}
protected override void OnLeave(EventArgs e)
{
SetValue(GetValue());
base.OnLeave(e);
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (IsValidChar(e.KeyChar) == false)
{
e.Handled = true;
return;
}
base.OnKeyPress(e);
}
public T Value
{
get { return GetValue(); }
set { SetValue(value); }
}
protected virtual T GetValue()
{
string s = GetValidatedText();
try
{
return (T)Convert.ChangeType(s, typeof(T));
}
catch {};
return m_lastValue;
}
protected virtual void SetValue(T value)
{
Text = value.ToString();
m_lastValue = value;
}
protected virtual string GetValidatedText()
{
return Text;
}
}
public class IntEditor : BaseEditor<Int32>
{
public bool AllowNegativeNumber
{
set
{
if (value)
m_filterString = "-0123456789";
else
m_filterString = "0123456789";
}
}
public IntEditor()
{
AllowNegativeNumber = true;
TextAlign = HorizontalAlignment.Right;
}
}
public class FloatEditor : BaseEditor<float>
{
public bool AllowNegativeNumber
{
set
{
if (value)
m_filterString = "-.0123456789";
else
m_filterString = ".0123456789";
}
}
public FloatEditor()
{
AllowNegativeNumber = false;
TextAlign = HorizontalAlignment.Right;
}
}
}