我目前在VS 2012工作。 .NET 4.5并使用mmc管理单元。 (我知道吗?!)
所以我跟着这个话题:
Is there a simple way to implement a Checked Combobox in WinForms
因为我想要一些类似于计划任务管理器的东西。
但是这个解决方案对我来说似乎不起作用。 弹出列表视图,但是当我尝试单击列表视图中的复选框时。 它给了我一个大中指并关闭了我的下拉列表。
有什么方法可以抑制组合框的“焦点丢失”关闭事件? 我可以,不要隐藏列表,但它永远不会隐藏。
例如:
// designer class
//
// comboBox1
//
this.comboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.comboBox1.DropDownHeight = 1;
this.comboBox1.DropDownWidth = 1;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.IntegralHeight = false;
this.comboBox1.Location = new System.Drawing.Point(256, 371);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(238, 21);
this.comboBox1.TabIndex = 5;
this.comboBox1.DropDown += new System.EventHandler(this.comboBox1_DropDown);
this.comboBox1.DropDownClosed += new System.EventHandler(this.comboBox1_DropDownClosed);
//
// lstWeekDays
//
this.lstWeekDays.CheckBoxes = true;
this.lstWeekDays.Location = new System.Drawing.Point(50, 63);
this.lstWeekDays.Name = "lstWeekDays";
this.lstWeekDays.Size = new System.Drawing.Size(263, 97);
this.lstWeekDays.TabIndex = 13;
this.lstWeekDays.Tag = "lstlstWeekDays";
this.lstWeekDays.UseCompatibleStateImageBehavior = false;
this.lstWeekDays.View = System.Windows.Forms.View.SmallIcon;
this.lstWeekDays.Visible = false;
// Code behind
public Form1()
{
InitializeComponent();
this.lstWeekDays.Items.Add("Monday");
this.lstWeekDays.Items.Add("Tuesday");
this.lstWeekDays.Items.Add("Wednesday");
this.lstWeekDays.Items.Add("Thursday");
this.lstWeekDays.Items.Add("Friday");
this.lstWeekDays.Items.Add("Saturday");
this.lstWeekDays.Items.Add("Sunday");
}
private void comboBox1_DropDown(object sender, EventArgs e)
{
lstWeekDays.Visible = true;
}
private void comboBox1_DropDownClosed(object sender, EventArgs e)
{
lstWeekDays.Visible = false;
}
将复选框添加到此列表而不是面板。