Tag: ondraw

覆盖ComboBox的DrawItem

我更改了各种控件的高亮颜色,我打算进行更多更改。 因此,我最好创建自己的控件并重用它们,而不是为每个控件进行更改。 我创建了一个新的用户控件,并inheritance自System.Windows.Forms.ComboBox 。 问题是我无法像onClick那样找到覆盖onDraw的方法。 那我该如何去改写呢? 这是我用于每个控件onDraw事件的代码 public void comboMasterUsers_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); Graphics g = e.Graphics; Brush brush = ((e.State & DrawItemState.Selected) == DrawItemState.Selected) ? Brushes.LightSeaGreen : new SolidBrush(e.BackColor); g.FillRectangle(brush, e.Bounds); e.Graphics.DrawString(comboMasterUsers.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds, StringFormat.GenericDefault); e.DrawFocusRectangle(); } 谢谢!