-
Notifications
You must be signed in to change notification settings - Fork 1
/
EXComboBox.cs
165 lines (126 loc) · 5.29 KB
/
EXComboBox.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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;
namespace EXControls {
class EXComboBox : ComboBox {
private Brush _highlightbrush; //color of highlighted items
public EXComboBox() {
_highlightbrush = SystemBrushes.Highlight;
this.DrawMode = DrawMode.OwnerDrawFixed;
this.DrawItem += new DrawItemEventHandler(this_DrawItem);
}
public Brush MyHighlightBrush {
get {return _highlightbrush;}
set {_highlightbrush = value;}
}
private void this_DrawItem(object sender, DrawItemEventArgs e) {
if (e.Index == -1) return;
e.DrawBackground();
if ((e.State & DrawItemState.Selected) != 0) {
e.Graphics.FillRectangle(_highlightbrush, e.Bounds);
}
EXItem item = (EXItem) this.Items[e.Index];
Rectangle bounds = e.Bounds;
int x = bounds.X + 2;
if (item.GetType() == typeof(EXImageItem)) {
EXImageItem imgitem = (EXImageItem) item;
if (imgitem.MyImage != null) {
Image img = imgitem.MyImage;
int y = bounds.Y + ((int) (bounds.Height / 2)) - ((int) (img.Height / 2)) + 1;
e.Graphics.DrawImage(img, x, y, img.Width, img.Height);
x += img.Width + 2;
}
} else if (item.GetType() == typeof(EXMultipleImagesItem)) {
EXMultipleImagesItem imgitem = (EXMultipleImagesItem) item;
if (imgitem.MyImages != null) {
for (int i = 0; i < imgitem.MyImages.Count; i++) {
Image img = (Image) imgitem.MyImages[i];
int y = bounds.Y + ((int) (bounds.Height / 2)) - ((int) (img.Height / 2)) + 1;
e.Graphics.DrawImage(img, x, y, img.Width, img.Height);
x += img.Width + 2;
}
}
}
int fonty = bounds.Y + ((int) (bounds.Height / 2)) - ((int) (e.Font.Height / 2));
e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(e.ForeColor), x, fonty);
e.DrawFocusRectangle();
}
public class EXItem {
private string _text = "";
private string _value = "";
public EXItem() {
}
public EXItem(string text) {
_text = text;
}
public string Text {
get {return _text;}
set {_text = value;}
}
public string MyValue {
get {return _value;}
set {_value = value;}
}
public override string ToString() {
return _text;
}
}
public class EXImageItem : EXItem {
private Image _image;
public EXImageItem() {
}
public EXImageItem(string text) {
this.Text = text;
}
public EXImageItem(Image image) {
_image = image;
}
public EXImageItem(string text, Image image) {
this.Text = text;
_image = image;
}
public EXImageItem(Image image, string value) {
_image = image;
this.MyValue = value;
}
public EXImageItem(string text, Image image, string value) {
this.Text = text;
_image = image;
this.MyValue = value;
}
public Image MyImage {
get {return _image;}
set {_image = value;}
}
}
public class EXMultipleImagesItem : EXItem {
private ArrayList _images;
public EXMultipleImagesItem() {
}
public EXMultipleImagesItem(string text) {
this.Text = text;
}
public EXMultipleImagesItem(ArrayList images) {
_images = images;
}
public EXMultipleImagesItem(string text, ArrayList images) {
this.Text = text;
_images = images;
}
public EXMultipleImagesItem(ArrayList images, string value) {
_images = images;
this.MyValue = value;
}
public EXMultipleImagesItem(string text, ArrayList images, string value) {
this.Text = text;
_images = images;
this.MyValue = value;
}
public ArrayList MyImages {
get {return _images;}
set {_images = value;}
}
}
}
}