User Control saving properties

S

Steve Long

Hello.
Can anyone tell me the proper way to save the properties of a user control
between design time and run time?

So, I've got this user control with the following properties:
BarColor1
BarColor2

I can access these properties in the property browser and change the colors.
But how to I have those changes persist between design time and run time for
the user control?
If the user of the control changes BarColor1 at design time, I want that to
persist to run time. And, if the user changes the color at run time, I want
that color to persist to the next instance of run time?
I'm using VS 2003.

Steve
 
R

RobinS

Save them to the <Settings> information for the project.

You can add them by double-clicking on "my project" in the
solution explorer. This brings up the project properties.
Click on the <Settings> tab.

Add settings here. Each setting must have a
unique name, such as BarColor1, BarColor2, etc.

For Type, pick the type of value that it is; this
prevents you from having to convert it. There's
probably something like System.Color, or System.Drawing.Color.

Set the scope to User.

Then in your code, when the user changes it, save it to
the settings:

My.Settings.BarColor1 = whatever (must be same type)


Then when you want to use it, use My.Settings.BarColor1
instead of a color. It will retrieve the value from the Settings
and use it.

The .Net runtime saves the settings when the application is
closed, and reads them when it is opened.

Robin S.
 
S

Steve Long

Robin, there is no Settings tab in VS 2003 that I can see. Do you have one
in VS 2003?

Steve
 
R

RobinS

Oh dear, I have VS2005. In that case, I'm sorry, but
I don't know what the solution is. Anyone else?

Robin S.
----------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top