473,385 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

On Application Setings in .NET 2.0 (Visual Studio 2005 Pro, C#)

Hello. I apologize for asking this question as the information I need is
availible via the MSDN library, however I cannot seemt o understand what I
need to do, so I'm asking here.

I have created application settings in Visual Studio (right-click on the
project, go to the settings tab, etc.) and have associated each of these
settings with a property on a form. This seems to be working right (i.e. if I
edit the default value of a setting, the setting on the form changes too, so
something must be working correctly).

I now want to save the settings to persist so that if the user opens the
program again, the same settings they had last time in each part of the forum
are still availible. How would I go about doing this?

The "how to" article in the MSDN implies that a seperate "Settings" object
has been created and that calling Settings.Save() in my closing method should
be sufficient. However, I cannot seem to access a Settings object within the
scope of my form. Do I need to create a wrapper class that extends
ApplicationSettingsBase, and if so, how would I go about doing this (the
article on ApplicationSettingsBase ha it applying to a form, however it
manually sets all the properties itself, and I'm guessing the form designer
does that automatically.

Thanks for your help,
Robert Fraser
Nov 28 '06 #1
3 4759
Hi,

Settings object for the settings file can be accessed in the following ways.

VB.Net: My.Settings
C#: [Project Namespace].Properties.Settings.Default.[SettingName]

and calling the Settings.Save method will do the trick (provided the
settings are user scoped).
Also if you are using VB.Net and
If you just want to save your setting upon shutdown there is a project level
property that does just about this.

Goto Project Properties -Application Tab

Check the
'Save My.Settings on Shutdown'
checkbox.
Regards,
Hameer Saleem

"xycos" wrote:
Hello. I apologize for asking this question as the information I need is
availible via the MSDN library, however I cannot seemt o understand what I
need to do, so I'm asking here.

I have created application settings in Visual Studio (right-click on the
project, go to the settings tab, etc.) and have associated each of these
settings with a property on a form. This seems to be working right (i.e. if I
edit the default value of a setting, the setting on the form changes too, so
something must be working correctly).

I now want to save the settings to persist so that if the user opens the
program again, the same settings they had last time in each part of the forum
are still availible. How would I go about doing this?

The "how to" article in the MSDN implies that a seperate "Settings" object
has been created and that calling Settings.Save() in my closing method should
be sufficient. However, I cannot seem to access a Settings object within the
scope of my form. Do I need to create a wrapper class that extends
ApplicationSettingsBase, and if so, how would I go about doing this (the
article on ApplicationSettingsBase ha it applying to a form, however it
manually sets all the properties itself, and I'm guessing the form designer
does that automatically.

Thanks for your help,
Robert Fraser
Nov 28 '06 #2
Hi Robert,

If you open the Solution Explorer in VS 2005 there should be a special node
named, "Properties" under your project node. If you expand that node you'll
see your "Settings.settings" file.

VS 2005 adds a namespace for your Settings class since it's in the
Properties folder. You'll notice that each setting you have defined has a
Typed property defined for it in the Settings class:

// example
Color aColor = Properties.Settings.Default.AColorSetting;

(Default is created by VS so that you can access the settings defined in the
project's properties dialog at runtime. These settings will be the ones
that you are binding to in the designer and may be persisted at runtime).

Changes to Application-scoped settings are not persisted at runtime, so they
are created as read-only properties. User-scoped settings, to the contrary,
provide properties that are read/write and can be persisted. User-scoped
settings are stored in a "user.config" file located in isolated storage.

The settings returned by Properties.Settings.Default can be a mixture of
settings with different scopes, as configured in the Settings editor.

You can modify and save your current User-scoped settings like this:

Properties.Settings.Default.AColorSetting = Color.Blue;
Properties.Settings.Default.Save();

In VS 2005, you can do the following to create a DataBinding between a
control's property and a User-scoped setting's property:

1. Select a control on the Form designer
2. Open the Properties window
3. In the categorical sort mode, scroll down to "Data"
4. Expand the ApplicationSettings node
5. Select a setting from the drop-down list next to one of the properties
6. If the property you want to bind to isn't available, click the ellipses
in the "(PropertyBinding)" item and find it in the dialog that is shown

Once a data-binding has been established, you can simply call Save on the
Settings class to persist any changes to the control's property without
having to first assign the value like in my previous example. The next time
the application is started, the persisted data will automatically be loaded
and assigned to the data-bound property when the Form is constructed.

Note that VS 2005 can be misleading since it appears to add a duplexed
binding when you select an Application-scoped setting for the value of a
control's property just like it would when you select a User-scoped setting,
when in fact it's simply serializing code (into the InitializeComponent
method) that reads the value from the setting's property into the control's
property. The "binding" is not duplexed since changes to Application-scoped
settings cannot be persisted at runtime. Application-scope "bindings" exist
only at design-time. Changes to a 'bound" property will have no effect on
the Settings class.

--
Dave Sexton

"xycos" <xy***@discussions.microsoft.comwrote in message
news:95**********************************@microsof t.com...
Hello. I apologize for asking this question as the information I need is
availible via the MSDN library, however I cannot seemt o understand what I
need to do, so I'm asking here.

I have created application settings in Visual Studio (right-click on the
project, go to the settings tab, etc.) and have associated each of these
settings with a property on a form. This seems to be working right (i.e.
if I
edit the default value of a setting, the setting on the form changes too,
so
something must be working correctly).

I now want to save the settings to persist so that if the user opens the
program again, the same settings they had last time in each part of the
forum
are still availible. How would I go about doing this?

The "how to" article in the MSDN implies that a seperate "Settings" object
has been created and that calling Settings.Save() in my closing method
should
be sufficient. However, I cannot seem to access a Settings object within
the
scope of my form. Do I need to create a wrapper class that extends
ApplicationSettingsBase, and if so, how would I go about doing this (the
article on ApplicationSettingsBase ha it applying to a form, however it
manually sets all the properties itself, and I'm guessing the form
designer
does that automatically.

Thanks for your help,
Robert Fraser

Nov 28 '06 #3
Thank you both for your detailed, prompt, and helpful responses. Have a great
day!

Best of wishes,
Robert Fraser
Nov 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bill Davy | last post by:
I am building a C++ program (main.exe) with VC6 which expects to call the Python DLL. When I start it (under the debugger), I get: "This application has failed to start because python24_d.dll was...
0
by: gerd | last post by:
Hello, I want to port an MFC Application from Visual Studio 6 MFC application to Visual C++ 2005 express edition beta. While building i get following error: ------ Build started: Project:...
1
by: Tetris | last post by:
I am preparing the MCAD Certification. I use the Visual Studio 2005. But I can't create Web application. There is only ASP.NET Web service project. Is it possible to develope ASP.NET web...
6
by: yaron.guez | last post by:
Whenever I create a new windows application from Visual Studio .NET 2003 in either C# or VB.NET upon running the compiled code (debugging or not) I receive a System.NullReferenceException...
0
by: alto | last post by:
After compeleting steps 1 to 5 of the Step-By-Step Guide to Converting Web Projects from Visual Studio .NET 2002/2003 to Visual Studio 2005...
1
by: David Lozzi | last post by:
Howdy, I've created an entire ecommerce site as a Web Site project (WSP) in VS2005. Now that i'm trying to publish it I'm finding that I should've used the ASP.Net Web Application (ANWA) project...
0
by: Stephen Thomas | last post by:
Hi there I wonder if any one has encountered this problem or can suggest what is wrong. I am trying the a procedure from the msn site but get the following message: Error 1 The type or...
1
by: lds | last post by:
I have Visual Studio 2005 Professional Edition installed with Service Pack 1. I have several solutions and projects that I have migrated from Visual Studio 2003 to 2005. In most cases the changes...
6
by: Author | last post by:
I have VS 2005 professional. Here is the version info: Microsoft Visual Studio 2005 Version 8.0.50727.762 (SP .050727-7600) &copy; 2005 Microsoft Corporation. All rights reserved. When I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.