定制C# combobox的下拉框
Contents
今天做了个小东西,需要定制combobox的下拉框,打开下拉框时如下图。

选择一个后,如下图。

实现的方法是需要把combobox的DrawoMode设置成OwnerDrawVariable,然后处理DrawItem事件,详见ComboBox.DrawItem Event (System.Windows.Forms)代码如下:
1 | private void cb_Risk_DrawItem(object sender, DrawItemEventArgs e) |
对了,我这里的代码都是用CopySourceAsHtml这个VS的addin粘进来的,对于VS2010,这篇文章CopyAsHtml in Visual Studio 2010 - AppliSec有一个workaround。