winforms - Dynamic flowlayoutpanel creation and dispose in c# -
i have created flowlayoutpanel dynamically in windows form using c# . have added 1 button in panel . can tell me how remove panel dynamically after button pressed? here coding :
flowlayoutpanel[] flws ; button[] butns ; ( int i=0; i<3; i++) { flws[i] = new flowlayoutpanel(); flws[i].name = "flw" + i; flws[i].location = new point(3,brh); flws[i].size = new size(317,122); flws[i].backcolor = color.darkcyan; flws[i].borderstyle = borderstyle.fixed3d; butns[i] = new button(); butns[i].click += new eventhandler(butns_click); butns[i].text = "submit"; butns[i].name = "but" + i; butns[i].location = new point(1100, 186 + brh); flws[i].controls.add(butns[i]); }
came quick, hope helps.
[edited meet requeriments].
using system; using system.collections.generic; using system.drawing; using system.windows.forms; namespace flowlayoutstackoverflow { public partial class form1 : form { public form1() { initializecomponent(); } private void form1_load(object sender, eventargs e) { //load 3 flp's (int = 0; < 3; i++) { var _flowlayoutpanel = new flowlayoutpanel(); _flowlayoutpanel.name = "flow" + i; _flowlayoutpanel.location = new point(30*i, 30*i); _flowlayoutpanel.size = new size(300, 30); _flowlayoutpanel.backcolor = color.darkcyan; _flowlayoutpanel.borderstyle = borderstyle.fixed3d; _flowlayoutpanel.disposed += _flowlayoutpanel_disposed; //dispose button var _button = new button(); _button.text = "dispose"; _button.name = "disposebutton" + i; _button.location = new point(1*i, 1*i); _button.mouseclick += _button_mouseclick; _flowlayoutpanel.controls.add(_button); this.controls.add(_flowlayoutpanel); } } private void _button_mouseclick(object sender, mouseeventargs e) { (sender button).parent.dispose(); } //notify disposal private void _flowlayoutpanel_disposed(object sender, eventargs e) { messagebox.show(string.format("disposed flowlayoutpanel name {0}", (sender flowlayoutpanel).name)); } } }
Comments
Post a Comment