using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//Make combo box draw mode to variable draw mode
//this will allow us to draw combo box in our style
comboBox1.DrawMode = DrawMode.OwnerDrawVariable;
//using DrawItem event we need to draw item
comboBox1.DrawItem += new DrawItemEventHandler(comboBox1_DraItemEvent);
string[] itm = { "123", "456", "789" };
comboBox1.Items.AddRange(itm);
}
private void comboBox1_DraItemEvent(object sender, DrawItemEventArgs e)
{
//draw back groud of the item
e.DrawBackground();
//Create a Image from a file
Image img = Image.FromFile(@"media_stop.png");
//Draw the image in combo box using its bound, here size of image is
// 10, 10 you can increase the size if you want
e.Graphics.DrawImage(img, e.Bounds.X, e.Bounds.Y, 15, 15);
//we need to draw the item as string because we made drawmode to ownervariable
e.Graphics.DrawString(comboBox1.Items[e.Index].ToString(), comboBox1.Font,
System.Drawing.Brushes.Black,
new RectangleF(e.Bounds.X + 15, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
//draw rectangle over the item selected
e.DrawFocusRectangle();
}
}
}