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
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
/// <summary>
/// Da es im Framework keine ImageComboBox gibt hatte ich einfach selber
/// eine geschrieben bzw. die vorhandene ComboBox erweitert.
/// Achtung: Man kann nur Items per Code hinzufügen also nicht im Designer,
/// da man im Designer kein ImageKey festlegen kann.
/// </summary>
/// <remarks>Tim Hartwig</remarks>
public class ImageComboBox : ComboBox
{
private ImageList mImageList = null;
public ImageComboBox()
{
this.DrawMode = DrawMode.OwnerDrawFixed;
}
public ImageList ImageList
{
get { return mImageList; }
set { mImageList = value; }
}
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
{
base.OnDrawItem(e);
e.DrawBackground();
e.DrawFocusRectangle();
if (e.Index >= 0)
{
if (this.Items[e.Index] is ImageComboItem)
{
if (mImageList != null)
{
ImageComboItem CurrItem = (ImageComboItem)this.Items[e.Index];
if (CurrItem.ImageIndex != -1)
{
this.ImageList.Draw(e.Graphics, e.Bounds.Left, e.Bounds.Top, CurrItem.ImageIndex);
e.Graphics.DrawString(CurrItem.Text, CurrItem.Font,
new SolidBrush(CurrItem.ForeColor),
e.Bounds.Left + mImageList.ImageSize.Width, e.Bounds.Top);
}
else
{
e.Graphics.DrawString(CurrItem.Text, CurrItem.Font,
new SolidBrush(CurrItem.ForeColor),
e.Bounds.Left + mImageList.ImageSize.Width, e.Bounds.Top);
}
}
}
else
{
e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds.Left, e.Bounds.Top);
}
}
}
}
public class ImageComboItem
{
private Color mForeColor = Color.Black;
private int mImageIndex = -1;
private object mTag = null;
private string mText = "";
private Font mFont;
public ImageComboItem(string Text, Font Font, Color ForeColor)
{
mText = Text;
mFont = Font;
mForeColor = ForeColor;
}
public ImageComboItem(string Text, Font Font, Color ForeColor, int ImageIndex)
{
mText = Text;
mFont = Font;
mForeColor = ForeColor;
mImageIndex = ImageIndex;
}
public Color ForeColor {
get { return mForeColor; }
set { mForeColor = value; }
}
public int ImageIndex {
get { return mImageIndex; }
set { mImageIndex = value; }
}
public object Tag {
get { return mTag; }
set { mTag = value; }
}
public string Text {
get { return mText; }
set { mText = value; }
}
public Font Font {
get { return mFont; }
set { mFont = value; }
}
public override string ToString()
{
return mText;
}
}
|