Click here to Skip to main content
15,898,745 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,
I have just started using the applications settings feature to save user and system data. The first time my application runs it finds a variety of paths and sets up some user data. User data is then saved at run time (last selected path etc).

I have added application settings to my main form and populate these on start up. But here is my problem. I can not figure out how to pass these settings on to sub-controls I have developed in a class library.

my project is structured thus

+ Solution 'codecontroller' (4 projects)
+ CodeControl (windows application
- Properties
-Settings.settings
- MainForm.cs
- app.config
+ DatabaseLib (class lib)
+ GuiClassLib (class lib)
+ GuiControlLib (class lib)
- properties
Setting.settings
- app.config
- ReleaseControlBrowser (User Control)
- BuildManager (user Control)

In this example ReleaseControlBrowser and BuildManager are included in the main form on separate tabs. What I need to happen is on start up I want to be able to pass settings from the main form to the sub controls (in the guicontrollib) and at run time for the sub-controls to update the settings when required (on close or triggered by an action such as build).

Can anyone give me advice on this? I have tried a number of solution including adding a link to the app.config in the GuiControlLib but this didn't seem to work.

thanks in advance,
G
Posted

Just for completeness. I have went for a singleton object to hold the global settings and combined this with settings.settings to allow these values to be stored between runs.

G
 
Share this answer
 
You can use class properties.

In your sub control main class have properties e.g.

C#
public class SubControl1
{
    public Int32 Id
    {
         get;
         set;
    }
    //set more properties here
   //you can access these properties using the this.Id within your class or SubControl1.Id outside your class
}


In from your main form you can set and get the properties for your sub-controls
There are many tutorials on google to help here e.g.
C#
SubControl1.Id = 1; //or get value from your application settings
 
Share this answer
 
Comments
grafne79 7-Sep-11 8:40am    
I was hoping for a method to pass all settings (or better yet reference) the settings on the main control. I dont really want to have to pass each setting to the sub-controls. also how do I update the app settings on the main form from the sub-control?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900