بنده کلاس زیر رو نوشتم. ItemImages لیستی از عکسهاست
using System.Drawing;
using System.Windows.Forms;
class ComboBoxWithIcon : ComboBox
{
private ImageList _itemImages;
private int _imageX, _imageY;
public ImageList ItemImages
{
get { return _itemImages; }
set
{
_itemImages = value;
if (value != null)
{
DrawMode = DrawMode.OwnerDrawVariable;
}
}
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
base.OnDrawItem(e);
e.DrawBackground();
if (e.Index < 0 || ItemImages == null) return;
string n = Items[e.Index].ToString();
RectangleF rectf;
if (RightToLeft == RightToLeft.Yes)
{
if (e.Index < ItemImages.Images.Count)
{
_imageX = e.Bounds.Right - ItemImages.ImageSize.Width;
_imageY = e.Bounds.Top + (e.Bounds.Height - ItemImages.ImageSize.Height)/2;
e.Graphics.DrawImage(ItemImages.Images[e.Index], _imageX, _imageY);
}
rectf = new RectangleF(e.Bounds.X, e.Bounds.Top, e.Bounds.Right - ItemImages.ImageSize.Width, e.Bounds.Bottom);
e.Graphics.DrawString(n, Font, Brushes.Black, rectf, new StringFormat(StringFormatFlags.DirectionRightToLef t));
}
else
{
if (e.Index < ItemImages.Images.Count)
{
_imageX = e.Bounds.Left;
_imageY = e.Bounds.Top + (e.Bounds.Height - ItemImages.ImageSize.Height)/2;
e.Graphics.DrawImage(ItemImages.Images[e.Index], _imageX, _imageY);
}
rectf = new RectangleF(e.Bounds.X + _itemImages.ImageSize.Width, e.Bounds.Y, e.Bounds.Right, e.Bounds.Bottom);
e.Graphics.DrawString(n, Font, Brushes.Black, rectf);
}
}
}