-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathComboBoxStyle.cs
More file actions
104 lines (88 loc) · 4.17 KB
/
ComboBoxStyle.cs
File metadata and controls
104 lines (88 loc) · 4.17 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
96
97
98
99
100
101
102
103
104
using ScriptEngine.Machine.Contexts;
using ScriptEngine.Machine;
using System.Collections;
using System.Collections.Generic;
namespace osf
{
[ContextClass("КлСтильПоляВыбора", "ClComboBoxStyle")]
public class ClComboBoxStyle : AutoContext<ClComboBoxStyle>, ICollectionContext, IEnumerable<IValue>
{
private int m_simple = (int)System.Windows.Forms.ComboBoxStyle.Simple; // 0 Выпадающий список отображается всегда, а текстовая часть является редактируемой. Это означает, что пользователь может ввести новое значение, а не ограничиваться выбором из существующих значений в списке.
private int m_dropDown = (int)System.Windows.Forms.ComboBoxStyle.DropDown; // 1 Нажав кнопку со стрелкой вниз получаем выпадающий список, текстовая часть которого является редактируемой. Это означает, что пользователь может ввести новое значение, а не ограничиваться выбором из существующих значений в списке. Это стиль по умолчанию.
private int m_dropDownList = (int)System.Windows.Forms.ComboBoxStyle.DropDownList; // 2 Нажав кнопку со стрелкой вниз получаем выпадающий список, текстовая часть которого не является редактируемой. Это означает, что пользователь не может ввести новое значение. Можно выбрать только значение из списка.
private List<IValue> _list;
public int Count()
{
return _list.Count;
}
public CollectionEnumerator GetManagedIterator()
{
return new CollectionEnumerator(this);
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<IValue>)_list).GetEnumerator();
}
IEnumerator<IValue> IEnumerable<IValue>.GetEnumerator()
{
foreach (var item in _list)
{
yield return (item as IValue);
}
}
[ContextProperty("Количество", "Count")]
public int CountProp
{
get { return _list.Count; }
}
[ContextMethod("Получить", "Get")]
public IValue Get(int index)
{
return _list[index];
}
[ContextMethod("Имя")]
public string NameRu(decimal p1)
{
return namesRu.TryGetValue(p1, out string name) ? name : p1.ToString();
}
[ContextMethod("Name")]
public string NameEn(decimal p1)
{
return namesEn.TryGetValue(p1, out string name) ? name : p1.ToString();
}
private static readonly Dictionary<decimal, string> namesRu = new Dictionary<decimal, string>
{
{2, "НеРедактируемый"},
{0, "Простой"},
{1, "Редактируемый"},
};
private static readonly Dictionary<decimal, string> namesEn = new Dictionary<decimal, string>
{
{2, "DropDownList"},
{0, "Simple"},
{1, "DropDown"},
};
public ClComboBoxStyle()
{
_list = new List<IValue>();
_list.Add(ValueFactory.Create(DropDown));
_list.Add(ValueFactory.Create(DropDownList));
_list.Add(ValueFactory.Create(Simple));
}
[ContextProperty("НеРедактируемый", "DropDownList")]
public int DropDownList
{
get { return m_dropDownList; }
}
[ContextProperty("Простой", "Simple")]
public int Simple
{
get { return m_simple; }
}
[ContextProperty("Редактируемый", "DropDown")]
public int DropDown
{
get { return m_dropDown; }
}
}
}