我希望有一个组合框,当用户将鼠标悬停在某个对象上时会发生一个事件,所以我必须让它有一个drawMode作为ownerDrawFixed。我试图让它看起来像一个普通的组合框但不能摆脱突出显示。因此,当用户单击它时,该对象将具有突出显示但文本仍然是黑色的,与文本变为白色时的正常文本不同。此外,当我关闭下拉时,它仍然突出显示不同于正常的组合列表。我包括一些图片,它不是那么重要,但我希望能够做到这一点。这是代码和图片:
private void Form1_Load(object sender, EventArgs e)
{
animals = new string[] { "hello", "good", "day" };
comboBox1.DataSource = animals;
}
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
float size = 0;
System.Drawing.Font myFont;
FontFamily family = null;
switch (e.Index)
{
case 0:
size = 8;
family = new FontFamily("Microsoft Sans Serif");
break;
case 1:
size = 8;
family = new FontFamily("Microsoft Sans Serif");
break;
case 2:
size = 8;
family = new FontFamily("Microsoft Sans Serif");
break;
}
e.DrawBackground();
myFont = new Font(family, size, FontStyle.Regular);
e.Graphics.DrawString(animals[e.Index], myFont, System.Drawing.Brushes.Black, Convert.ToInt32(e.Bounds.X), Convert.ToInt32(e.Bounds.Y));
e.DrawFocusRectangle();
}
看看他们的样子