c# - How to Clone a Windows Forms Control -
i have c# form has groupbox. user must input desired number (integer) , when user clicks "add", group box must duplicated , pasted on same form based on number user inputted. how create exact copy of groupbox , paste in same form? please see attached screenshot.
any appreciated. thanks
i used sriram's code form adds 2 groupbox:
private void button1_click(object sender, eventargs e) { int containers = 0; int.tryparse(textbox1.text, out containers); (int = 0; < containers; i++) { flowlayoutpanel1.controls.add(groupbox1); } }
i'll suggest create user control has groupbox shown child controls.
let's call myusercontrol
when create instance of myusercontrol
controls groupbox.
to show controls without overlapping each other can use flowlayoutpanel
arranges controls automatically. in button click code you'd write
void addbutton_click(object sender, eventargs e) { int contaniners = 0; int.tryparse(txtcontainers.text, out contaniners); (int = 0; < contaniners; i++) { flowlayoutpanel.controls.add(new myusercontrol()); } }
Comments
Post a Comment