Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
actually i want to add different image and color to combobox arrow icon,so what can i do ,i was tried this specific code but problem not solved

Mycode:

public sealed class ColorSelector : ComboBox
{
public ColorSelector()
{
DrawMode = DrawMode.OwnerDrawFixed;
DropDownStyle = ComboBoxStyle.DropDownList;
}

protected override void OnDrawItem(DrawItemEventArgs e)
{
e.DrawBackground();

e.DrawFocusRectangle();

if (e.Index >= 0 && e.Index < Items.Count)
{
DropDownItem item = (DropDownItem)Items[e.Index];

e.Graphics.DrawImage(item.Image, e.Bounds.Left, e.Bounds.Top);

e.Graphics.DrawString(item.Value, e.Font, new SolidBrush(e.ForeColor), e.Bounds.Left + item.Image.Width, e.Bounds.Top + 2);
}

base.OnDrawItem(e);
}
}
public sealed class DropDownItem
{
public string Value { get; set; }

public Image Image { get; set; }

public DropDownItem()
: this("")
{ }

public DropDownItem(string val)
{
Value = val;
Image = new Bitmap(16, 16);
using (Graphics g = Graphics.FromImage(Image))
{
using (Brush b = new SolidBrush(Color.FromName(val)))
{
g.DrawRectangle(Pens.White, 0, 0, Image.Width, Image.Height);
g.FillRectangle(b, 1, 1, Image.Width - 1, Image.Height - 1);
}
}
}

public override string ToString()
{
return Value;
}
}
Posted

1 solution

After a quick look I'd say you should not call
base.OnDrawItem(e);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900