How to handle events of dynamically added checkbox on windows form

前端 未结 4 841
迷失自我
迷失自我 2021-01-27 02:58

I am able to add checkbox dynamically on windows form and add data value to its text property. On click of any checkbox I have run a procedure which will make certain other chec

4条回答
  •  孤城傲影
    2021-01-27 03:15

    if the name of the dynamically added checkbox is c, the answer is as below:

    c.CheckedChanged += c_CheckedChanged;
    

    and c_CheckedChanged is as below:

     private void c_CheckedChanged(object sender, EventArgs e)
        {
           if (((CheckBox)sender).Checked)
           {
              ((CheckBox)(this.Controls.Find("c1", false))[0]).Enabled = false;
           }
        }
    

    which c1 is the name of the checkbox you want to disable.

提交回复
热议问题