In Run Time: Add Controls to a Form and Save Changes


  I know how to add & remove controls in a form at Run-Time, but I need to know HOW TO SAVE THOSE CHANGES, for example:

  If a make a form (at desing time) with two commandbuttons inside a picturebox, and I load the form...
  After I add 3 new commandbuttons at run time and Unload the form, it doesn't save the changes made so the form ends having 2 commandbuttons instead of 5.

  How can i do that ???
  Does anyone have a clue about that ???

  I'll apreciate your help...
Who is Participating?
JaganMohanConnect With a Mentor Commented:
Basically when you are adding a control at run time means you are referring the existing control and creating a object of the same type. So you are writing code for this, it is "dynamic" controls creation. The advantage of this over design time controls is memory. Suppose in a form if you need 100 textbox controls then instead of taking 100 textbox control at design time you can take only 1 control at design time and u can creating 100 at run time.

This case is upto VB5. Now in VB6 you can create controls with out any control at design time
MCP072099Author Commented:
Edited text of question.
Basically, you can't. Remember that VB is *compiled*, only those controls created at design time will automatically appear at runtime. If you create controls *dynamically* they're just that *DYNAMIC*. They vanish as soon as the form is unloaded.

Now you can save settings in a file or the registry and automatically recreate the dynamic controls when the page reloads, but they'll *still* be dynamic controls.


7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

MCP072099Author Commented:
 Basically, I *KNOW* that VB is *compiled* but as you may know, I'm looking for alternatives and you didn't tell me exactly how to do that (sample code)...

  However, if you are in the 5th place of the "EXPERTS", you should be more polite with your answers refered to "The NON-EXPERTS"
  Thanks anyway...
Save the control's left, top, width, height, caption, default, etc. in a file or registry and retrieving it at form_load time is the answer to your question.

File I/O and/or registry access is another whole question. You can check the PAQ's for both if you want.
MCP072099Author Commented:
Thanks KDivad i'll do that
MCP072099Author Commented:
Thanks KDivad i'll do that
If you want to be really basic, you could save details of your controls in an ini file. That way if you or your users delete the app, you dont need to delete registry entries.

I answered a question on updating controls values from ini files a while back. For more info try Question 10179580

Good luck.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.