重写combobox

重写combobox事件心得:

一、新建一个类ComboboxEx,继续combobox。

二、设置DrawMode = DrawMode.OwnerDrawFixed,这步很重要。

三、重写OnDrawItem事件

四、在工具箱拖入ComboboxEx控件,完成。

using System; using System.Windows.Forms; namespace combox { public class ComboBoxEx : ComboBox { public ComboBoxEx() { DrawMode = DrawMode.OwnerDrawFixed; } protected override void OnDrawItem(DrawItemEventArgs e) { base.OnDrawItem(e); MessageBox.Show("aaa"); } } } 

你可能感兴趣的:(Class,工具)