110,536
社区成员
发帖
与我相关
我的任务
分享
public Form1()
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
}
void Form1_Load(object sender, EventArgs e)
{
comboBox1.DrawMode = DrawMode.OwnerDrawFixed;
comboBox1.DrawItem += new DrawItemEventHandler(comboBox1_DrawItem);
comboBox1.Items.Add("sd1");
comboBox1.Items.Add("sd2");
comboBox1.Items.Add("sd3");
}
protected void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
ComboBox cb = sender as ComboBox;
Graphics g = e.Graphics;
Pen p = new Pen(Color.Blue, 1);
g.DrawRectangle(p, e.Bounds.X + 1, e.Bounds.Y + 1, 12, 12);
if (e.Index == cb.SelectedIndex)
g.DrawString("√", new Font(FontFamily.GenericSerif, 10), Brushes.Red,
e.Bounds.Location, StringFormat.GenericDefault);
g.DrawString(cb.GetItemText(cb.Items[e.Index]), new Font(FontFamily.GenericSerif, 9),
Brushes.Black, 15, e.Bounds.Y + 1, StringFormat.GenericDefault);
}