Question Create New Setting

pjfatboy

Active member
Joined
Nov 30, 2012
Messages
35
Programming Experience
Beginner
Hey, in my project I can create a new form at the click of a button. My question is, how do I create a new setting so that I can save location and other info about that form after the form has been created?
VB.NET:
My.Settings.Item?????
 
Hi,

As far as I am aware you are not able to create settings at runtime. This can only be done within the IDE. That said, the best that I can offer to achieve this at runtime is to create a StringCollection setting which you can then add to as you would to any other array in .NET and which can then be recalled each time you run your project.

To do this, in your Settings Type, select Browse then System>System.Collections.Specialized>StringCollection. (using VS2010)

Hope that helps.

Cheers,

Ian
 
Are you talking about at design time or at run time? If the former then you add settings on the Settings page of the project properties. If the latter then you don't. Settings are created at design time, not run time. It you want to be able to save a specific set of data for an arbitrary number of forms at run time then you should define a class that represents that set of data, i.e. has a property for each value, then save the data to a file at shutdown, either one form's form of data per file or the whole collection in one file.
 
Ok, let me see if I have this right. I create forms at Runtime and they have a textbox on them. I need to save each form.name, form.top, form.left and textbox.text for each form. So in the settings collections I would save the names to a collection, form.top to a different collection and so on?
 
Ok, let me see if I have this right. I create forms at Runtime and they have a textbox on them. I need to save each form.name, form.top, form.left and textbox.text for each form. So in the settings collections I would save the names to a collection, form.top to a different collection and so on?

If you want to use application settings without any additional effort then yes. You can get a custom type to save to application settings with a bit of extra effort, or you can just not use settings at all and save your custom type, or a list of your custom type, to a separate file.
 
Back
Top