我有一个带有以下代码的用户控件:
public partial class ColorComboBox : ComboBox
{
public ColorComboBox()
{
InitializeComponent();
this.DropDownStyle = ComboBoxStyle.DropDownList;
this.DrawMode = DrawMode.OwnerDrawFixed;
string[] colorNames = System.Enum.GetNames( typeof( KnownColor ) );
this.Items.AddRange( colorNames );
}
protected override void OnDrawItem( DrawItemEventArgs e )
{
if ( e.Index < 0 ) return;
this.SuspendLayout();
string s = (string)this.Items[ e.Index ];
using ( Brush b = new SolidBrush( Color.FromName( s ) ) )
{
e.Graphics.DrawRectangle( Pens.Black, 2, e.Bounds.Top + 1, 20, 11 );
e.Graphics.FillRectangle( b, 3, e.Bounds.Top + 2, 19, 10 );
e.Graphics.DrawString( s, this.Font, Brushes.Black, 25, e.Bounds.Top );
}
e.DrawFocusRectangle();
this.ResumeLayout();
}
}
将此 ComboBox 的实例添加到表单后,我遇到了一个奇怪的问题;鼠标指针下的每个项目都将条目更改为粗体。
有谁知道为什么会这样?
谢谢。