forked from 0000duck/VisionEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCComboBox.cs
More file actions
134 lines (127 loc) · 3.5 KB
/
CComboBox.cs
File metadata and controls
134 lines (127 loc) · 3.5 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Controls.Properties;
namespace Controls
{
public delegate void DSelectedIndexChanged();
public partial class CComboBox : UserControl
{
public CComboBox()
{
InitializeComponent();
cbx_item.Items.AddRange(Items);
}
/// <summary>
/// 选中项改变事件
/// </summary>
public event DSelectedIndexChanged SelectedIndexChanged;
/// <summary>
/// 选中项索引
/// </summary>
private int _selectedIndex = -1;
public int SelectedIndex
{
get { return _selectedIndex; }
set
{
_selectedIndex = value;
cbx_item.SelectedIndex = value;
}
}
/// <summary>
/// 文本
/// </summary>
private string _text = string.Empty;
public string TextStr
{
get { return _text; }
set
{
_text = value;
cbx_item.Text = value;
}
}
/// <summary>
/// 是否可以编辑
/// </summary>
private bool _canEdit = false;
public bool CanEdit
{
get { return _canEdit; }
set
{
_canEdit = value;
if (value)
cbx_item.DropDownStyle = ComboBoxStyle.DropDown;
else
cbx_item.DropDownStyle = ComboBoxStyle.DropDownList;
}
}
/// <summary>
/// 项
/// </summary>
private string[] _items = new string[] { };
public string[] Items
{
get { return _items; }
set
{
_items = value;
cbx_item.Items.Clear();
cbx_item.Items.AddRange(value);
}
}
/// <summary>
/// 删除所有项
/// </summary>
public void Clear()
{
Items = new string[] { };
cbx_item.Items.Clear();
}
/// <summary>
/// 添加项
/// </summary>
/// <param name="item">项</param>
public void Add(string item)
{
string[] items = new string[Items.Length + 1];
for (int i = 0; i < Items.Length; i++)
{
items[i] = Items[i];
}
items[Items.Length] = item;
Items = items;
}
private void cbx_item_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedIndex = cbx_item.SelectedIndex;
TextStr = cbx_item.Text;
if (SelectedIndexChanged != null)
SelectedIndexChanged();
}
private void ComboBox_Enter(object sender, EventArgs e)
{
lbl_line.Height = 2;
lbl_line.BackColor = Color.FromArgb(18, 150, 219);
btn_showItem.Image = Resources.BlueImage;
}
private void ComboBox_Leave(object sender, EventArgs e)
{
lbl_line.Height = 1;
lbl_line.BackColor = Color.Gray;
btn_showItem.Image = Resources.GrayImage;
}
private void btn_showItem_Click(object sender, EventArgs e)
{
cbx_item.DroppedDown = true;
}
}
}