-
Notifications
You must be signed in to change notification settings - Fork 402
Expand file tree
/
Copy pathSettingsTextBox.cs
More file actions
54 lines (47 loc) · 1.05 KB
/
SettingsTextBox.cs
File metadata and controls
54 lines (47 loc) · 1.05 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
using System;
using System.ComponentModel;
using System.Reflection;
using System.Windows.Forms;
namespace ReClassNET.UI
{
class SettingsTextBox : TextBox, ISettingsBindable
{
private PropertyInfo property;
private Settings source;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string SettingName
{
get { return property?.Name; }
set { property = typeof(Settings).GetProperty(value); ReadSetting(); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Settings Source
{
get { return source; }
set { source = value; ReadSetting(); }
}
private void ReadSetting()
{
if (property != null && source != null)
{
var value = property.GetValue(source);
if (value is string)
{
Text = (string)value;
}
}
}
private void WriteSetting()
{
if (property != null && source != null)
{
property.SetValue(source, Text);
}
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
WriteSetting();
}
}
}