c# - How can I save button which was dynamically created -


the following code dynamically creates button @ run time in windows forms c#. after closing / opening program button disappears (not saved). think button properties saved in designer.cs (if correct) not know how save there. knows how can save button has been dynamically created? thank

 private void button1_click(object sender, eventargs e)     {         // create button object          button dynamicbutton = new button();          // set button properties         dynamicbutton.height = 40;         dynamicbutton.width = 300;         dynamicbutton.backcolor = color.red;         dynamicbutton.forecolor = color.blue;         dynamicbutton.location = new point(20, 150);         dynamicbutton.text = "i dynamic button";         dynamicbutton.name = "dynamicbutton";         dynamicbutton.font = new font("georgia", 16);           dynamicbutton.click += new eventhandler(dynamicbutton_click);           controls.add(dynamicbutton);      } 

if create buttons dynamically, cannot saved in designer.

one way around be:

when created button, store information need recreate button in custom file (say xmls). information may include name of button, size, position, text, fore color, color etc need recreate button.

then, on form load. if find entry in custom file, recreate button using info. if not find entry of button, not create on form.

but whenever create button dynamically create entry in custom file , whenever delete it, delete entry.

if wish, replace custom file database table.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -