先看效果:
1 建立Winform窗体工程
2.创建类 ComboBoxMutiSelect
-- 继承于CombBox
-- 设置控件双缓冲属性
-- 添加私有属性 _IsMultiSelect
-- 添加属性 IsMultiSelect
class ComboBoxMutiSelect : ComboBox
{
private bool _IsMultiSelect;
public bool IsMultiSelect { get => _IsMultiSelect; set => _IsMultiSelect = value; }
public ComboBoxMutiSelect()
{
SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint, true);
UpdateStyles();
}
}
3.创建一个对话框,添加ComboBox控件,假设该控件的对象为 comboBox1
打开对话框的设计代码:对话框名字.Desiger.cs
--修改控件声明
将
private System.Windows.Forms.ComboBox comboBox1;
改为
private ComboBoxMutiSelect comboB