-
Notifications
You must be signed in to change notification settings - Fork 1
/
StringSelectionControl.cs
106 lines (93 loc) · 2.77 KB
/
StringSelectionControl.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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace NFL2K5Tool
{
public partial class StringSelectionControl : UserControl
{
public StringSelectionControl()
{
InitializeComponent();
}
public override string Text
{
get { return mLabel.Text; }
set { mLabel.Text = value; }
}
[EditorBrowsable(EditorBrowsableState.Always)]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Bindable(true)]
public ComboBoxStyle DropDownStyle
{
get { return mComboBox.DropDownStyle; }
set { mComboBox.DropDownStyle = value; }
}
public virtual string Value
{
get
{
string retVal = "";
if (mComboBox.SelectedItem != null)
retVal = mComboBox.SelectedItem.ToString();
return retVal;
}
set
{
int index = mComboBox.Items.IndexOf(value);
if (index > -1)
mComboBox.SelectedIndex = index;
}
}
private Type mRepresentedValue = typeof(string);
/// <summary>
/// For controls tied to an enum, this should be set to the value represented by the control.
/// </summary>
public Type RepresentedValue
{
get { return mRepresentedValue; }
set
{
if (value != null && value.IsEnum)
{
mRepresentedValue = value;
SetItems( Enum.GetNames(mRepresentedValue));
}
}
}
/// <summary>
/// Set the values for the control
/// </summary>
public void SetItems(object[] values)
{
mComboBox.Items.Clear();
mComboBox.Items.AddRange(values);
}
public event EventHandler ValueChanged;
private void mComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
OnValueChanged(e);
}
protected virtual void OnValueChanged(EventArgs e)
{
if (ValueChanged != null)
ValueChanged(this, e);
}
private void mComboBox_Enter(object sender, EventArgs e)
{
this.BackColor = Color.Moccasin;
}
private void mComboBox_Leave(object sender, EventArgs e)
{
this.BackColor = Parent.BackColor;
}
public void SetToInitialValue()
{
this.mComboBox.SelectedIndex = 0;
}
}
}