Saving User and Application Settings in WinForms

January 22, 2009 | By

Options Trading Kaskus Review Binary Signals The Site, On Which Most Volatile Couples On Forex http://curlyweave.org/?options=Binary-Option-Trading-In-Iraq Binary Option Trading In Iraq http://indulinursery.co.za/?topic=Islamabad-Stock-Exchange-Jobs-Western-Sahara Islamabad Stock Exchange Jobs Western Sahara http://zencio.com/?opt=Demand-Of-The-Offer-Forex Demand Of The Offer Forex Demand Of The Offer Forex http://indulinursery.co.za/?topic=Islamabad-Stock-Exchange-Jobs-Western-Sahara Islamabad Stock Exchange Jobs Western Sahara Each setting has four properties: name, type, value, and scope. The type can be a data type or an object. The scope can be user or application. The main difference between them is settings with application scope are read only at run time, while settings with user scope are read/write at run time.

Creating a New Settings

To start creating new settings, from the Solution Explorer right-click on the project node and select Properties, or expand the Properties node and double-click the .setting file. And then enter the name, type, scope and value for each setting.

Project Settings

 

Manipulating the Settings

To read and save the value of a setting in C# use the Properties object. The following example uses a TextBox and 2 Buttons named newValueTextBox, displayButton and saveButton respectively.

Filed in: WinForms | Tags: ,

Comments (9)

  1. Nisse

    Hello

    When I use this row The Site, On Which Most Volatile Couples On Forex Properties.Settings.Default.SQLFormsTestConnectionString = tbConnectionString.Text;

    I get compiler error. Options Trading Kaskus Review Binary Signals Inventory.Properties.Settings.SQLFormsTestConnectionString’ cannot be assigned to — it is read only

    So… what is your solution to this and it seams that there is none.

  2. Hello Nisse, Could you give me some more details like, did you create SQLFormsTestConnectionString using the Settings tab and what is the scope?

  3. me too

    I get cannot be assigned to — it is read only trying to assign to a setting. this doesn’t work. application scope.

  4. It seems like both of you are getting the same error, you are trying to assign a value to a setting that has an application scope. Settings with application scope are meant for things like connection strings, which the user cannot change at run time.

    So if that’s the case just delete the setting and create a new one with the same name and change the scope to User. That should solve it.

  5. I am not very happy that people keep saying things like Change Application Settings, when in fact they are not showing how to change application settings.. They are showing how to change User Settings at run time. I did not find this helpful at all.

  6. Ch. adeel

    I am declaring different Names keeping their scope user type bool and default value to false. When a user logs in, i get all the permissions assigned to him and update settings accordingly so that i could access them in my whole project and i don’t have to bring them from my database again and again and don’t have to store them somewhere else as well.

    Please let me know if its the correct idea or if you have better idea than this.

  7. Deepak

    Ver nice article… Thanks for giving this……

  8. Sam

    It doesn’t work if you put your application in windows startup. I always get the variables null. But if i start the application by the icon it works well. Don’t know how to fix this…

  9. Just did it.
    Thanks!