Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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

Posted on 1999-07-20
Medium Priority
Last Modified: 2010-04-30

  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...
Question by:MCP072099
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Author Comment

ID: 1526109
Edited text of question.
LVL 12

Expert Comment

ID: 1526110
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.



Author Comment

ID: 1526111
 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...
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 1526112
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.

Author Comment

ID: 1526113
Thanks KDivad i'll do that

Author Comment

ID: 1526114
Thanks KDivad i'll do that

Expert Comment

ID: 1526115
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.
LVL 13

Expert Comment

ID: 1526116

Accepted Solution

JaganMohan earned 200 total points
ID: 1526117
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question