嘿。我对 ComboBox 中的荧光笔有疑问。最近,我不得不将 ComboBox 中的某些项目变灰,我通过手动(以编程方式)在ComboBox中绘制字符串来做到这一点。在DrawMode.NORMAL下的 .NET 组合框中,当您单击箭头时,荧光笔将自动出现,并且荧光笔的背景颜色默认为近蓝色。问题是当我们将鼠标移到一个项目上时,悬停项目的前景色变为白色,但是当我们手动绘制项目时(DrawMode.OwnerDrawVariable)它不起作用。你能帮我解决这个问题吗??
这就是我将项目变灰的方式,
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
int index = e.Index;
CombinationEntry aFunction = comboBox1.Items[index] as CombinationEntry; //CombinationEntry is a custom object to hold the gray info. Gray if not available and black if available
if (aFunction.myIsAvailable)
{
e.Graphics.DrawString(aFunction.ToString(), new Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.Black, new Point(e.Bounds.X, e.Bounds.Y));
}
else
{
e.Graphics.DrawString(aFunction.ToString(), new Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.Gray, new Point(e.Bounds.X, e.Bounds.Y));
}
}