c# - dynamically changing picture box -
i dynamically create several picture box, , eventhandler. when user click on picturebox, program should delete tрis item. (the item user selected)
i try
for (int = 1; <= sunduki; i++) { picturebox pbobj = new picturebox(); pbobj.location = new system.drawing.point(i * 100, 101); pbobj.name = "picturebox" + i.tostring(); pbobj.size = new system.drawing.size(108, 80); pbobj.tabindex = i; pbobj.backgroundimage = image.fromfile(@"syndyk1.jpg"); pbobj.backgroundimagelayout = imagelayout.zoom; pbobj.click += new system.eventhandler(pb_click); pb.add(pbobj); controls.add(pb[pb.count - 1]);}
and in pb_click
private void pb_click(object sender, eventargs e) { pb[this].visible = false; }
but have error. (pb list picturebox)
the sender argument object has been clicked, in case picturebox object.
private void pb_click(object sender, eventargs e) { var pb = sender picturebox; if(pb != null) { pb.visible = false; } }
note: doesn't delete picture box, makes not visible. controls deletion handled disposal of form.
Comments
Post a Comment