Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am pretty new to the .NET framework so please bare with me. I am writing a time counter in C#, that counts the amount of time that has elapsed since a particular moment in time. That moment in time, as of right now, is hard coded. I would like that to be configurable. That and a couple of other values.

So, I have created a windows form and it has two user controls on it: one that is the main screen, and another that is the config screen. The application opens on the main screen and I can then use a button to get to the config screen.

What I want to do is to go into the config screen, enter my name and age in a textbox, enter a certain date (possibly with the date-time picker) and click a save button. Those values that I entered should then display in the appropriate places on the main screen, until I go back to the config screen and enter new values and save them.

How would I go about doing that?

share|improve this question

closed as not a real question by Oded, FrustratedWithFormsDesigner, Yannis Rizos, pdr, Otávio Décio Jan 12 '12 at 1:58

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

4  
Hi Tim, what are you interested in: code or a general high level approach? And in the future, please capitalize your Is and try to use titles that are in the form of a question. –  Yannis Rizos Jan 11 '12 at 20:20
2  
You might want to look at msdn.microsoft.com/en-us/library/k4s6c3a0.aspx –  FrustratedWithFormsDesigner Jan 11 '12 at 20:23
    
I am interested in both high level approach or best practices, as well as code. –  Tim Jan 11 '12 at 20:48
add comment

2 Answers

up vote 6 down vote accepted

This sounds like a work for user settings.

Basically, you define the settings you want to have in the designer table. And then you access them by using properties of Settings.Default. When you're done, save them using Settings.Default.Save().

The user settings are saved in a directory in the user's profile.

share|improve this answer
    
Worked Beautifully!! Thanks for your help everyone and svick! The only thing is that i have to close and re-open the program in order to see the changes. –  Tim Jan 11 '12 at 22:27
    
What do you mean? If you change the value of those properties and then read them, you will see the changed values. –  svick Jan 11 '12 at 23:14
    
Yea, it's a problem with my original code that is keeping it from reflecting the changes immediately but as far as the settings go, solution worked great. –  Tim Jan 12 '12 at 14:15
add comment

It sounds like you are not looking for application settings, but rather personalization. Application settings (such as you get with using the app.config file) give you one group of settings per application. I'm guessing from your question that you want one group of settings per user. I'm not aware of any "out of the box" personalization features that come with Windows Forms. ASP.NET has providers for it but I think they are specific to that platform.

That said, it isn't that hard to roll your own. A google search of "Windows Forms personalization" gives a lot of hits that show a lot of different approaches. You could store this data in a database (such as in a User table), or in a file on disk (or in Isolated Storage), or in the registry. There are a lot of options, and it would be hard to recommend one without understanding more about your specific situation.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.