c# - Multiple CheckedChanged event on programmatically added checkboxes -


i want able assign each checkbox it's own richtextbox

i'm making richtextboxes, i'm making checkboxes how can "link" them together?

for example :

        // richtextbox 1 - > checkbox 1 = false         // richtextbox 2 - > checkbox 2 = true         // richtextbox 3 - > checkbox 3 = true         // richtextbox 4 - > checkbox 4 = false 

this code:

int n = todoitems.count;         richtextbox[] richtextboxes = new richtextbox[n];         checkbox[] checkboxes = new checkbox[n];         (int = 0; < n; i++)         {             //creating richtextbox             richtextboxes[i] = new richtextbox();             richtextboxes[i].name = "tb" + i.tostring();             richtextboxes[i].text = todoitems[i].tostring();             richtextboxes[i].location = new system.drawing.point(130, (10 + (60 * i)));             richtextboxes[i].size = new system.drawing.size(300, 50);             richtextboxes[i].visible = true;             richtextboxes[i].readonly = true;             richtextboxes[i].selectionalignment = horizontalalignment.center;             richtextboxes[i].backcolor = color.white;             todolist.controls.add(richtextboxes[i]);              //creating checkboxes             checkboxes[i] = new checkbox();             checkboxes[i].name = "cb" + i.tostring();             checkboxes[i].text = "";             checkboxes[i].location = new system.drawing.point(440, (30 + (60 * i)));             checkboxes[i].size = new system.drawing.size(18, 17);             checkboxes[i].visible = true;             checkboxes[i].checkedchanged += new eventhandler(this.checkedchange);             todolist.controls.add(checkboxes[i]);         } 

i have modified code please see below, can access desired rich text box on checkbox click.

richtextbox[] richtextboxes { get; set; }         checkbox[] checkboxes { get; set; }          private void form1_load(object sender, eventargs e)         {             int n = todoitems.count;              richtextboxes = new richtextbox[n];              checkboxes = new checkbox[n];             (int = 0; < n; i++)             {                 //creating richtextbox                 richtextboxes[i] = new richtextbox();                 richtextboxes[i].name = "tb-" + i.tostring();                 richtextboxes[i].text = todoitems[i].tostring();                 richtextboxes[i].location = new system.drawing.point(130, (10 + (60 * i)));                 richtextboxes[i].size = new system.drawing.size(300, 50);                 richtextboxes[i].visible = false;                 richtextboxes[i].readonly = true;                 richtextboxes[i].selectionalignment = horizontalalignment.center;                 richtextboxes[i].backcolor = color.white;                 todolist.controls.add(richtextboxes[i]);                  //creating checkboxes                 checkboxes[i] = new checkbox();                 checkboxes[i].name = "cb-" + i.tostring();                 checkboxes[i].text = "";                 checkboxes[i].location = new system.drawing.point(440, (30 + (60 * i)));                 checkboxes[i].size = new system.drawing.size(18, 17);                 checkboxes[i].visible = true;                 checkboxes[i].checkedchanged += checkbox1_checkedchanged;                 todolist.controls.add(checkboxes[i]);             }         }          void checkbox1_checkedchanged(object sender, eventargs e)         {             checkbox cb = sender checkbox;              string cbname = cb.name;             int sbnumber = int.parse(cbname.split('-')[1]);              richtextboxes[sbnumber].visible = true; // can desired richtextbox here , can thing :)           } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -