如何在ListBox中添加CheckBox

如题所述

  实现其实很简单,只是我们在通过ListBox的Controls属性添加CheckBox时,要设置CheckBox的Location值,不然,添加多个CheckBox会只显示一个。如下代码所示:

代码

string[] list = new string[] { "张三", "李四", "王五" };

int x = 0, y = 0;
foreach (string item in list)
{
      CheckBox cb = new CheckBox();
      cb.Text = item;
      cb.Location = new Point(x, y);
      clbInvisibleColumn.Controls.Add(cb);
      y += 22;
}

温馨提示:答案为网友推荐,仅供参考
相似回答