Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Saving and Restoring Application Settings

, 15 Mar 2003
The Savior class makes it simple to save and restore application settings using the registry or a binary file.
savior.zip
Savior.exe
saviorsource.zip
App.ico
Savior.csproj.user
// =====================================================================
//
// Savior - Simplify Saving and Restoring Application Settings
//
// by Jim Hollenhorst, jim@ultrapico.com
// Copyright Ultrapico, March 2003
// http://www.ultrapico.com
//
// =====================================================================
using System;
using System.Drawing;

namespace SaveAndRestore
{
	/// Settings is the class in which all application settings are stored. This must
	/// be customized for each application and multiple such classes may be defined
	/// to facilitate more complex scenarios. The suggested name for the class is
	/// "Settings", but any name may be used since an instantiation of this class is
	/// passed to another class ("Savior") to do the work.
	/// 
	/// In order to support binary serialization to a file, the class should be marked
	/// with the [Serializable] attribute, as shown here
	/// 
	/// All default values should be specified in this class. These will be used if the
	/// corresponding information is not found in the registry.
	
	/// <summary>
	/// Any data that is desired to be saved should be stored in this class
	/// as a public field. It is suggested that most variables be given default
	/// values within this class. The class should be defined with the "Serializable"
	/// attribute to facilitate file serialization. Properties should not be defined.
	/// </summary>

	[Serializable]
	public class Settings
	{
		public string Text="Try changing this string!";
		public bool Check=true;
		public bool Radio=false;
		public decimal TheNumber=55;
		public Color BackColor=Color.Aqua;
		public Point Location = new Point(100,100);
		public Size TheSize=new Size(530,435);
		public Thing thing = Thing.Frog;
		public string[] SomeStrings=
		{
			"You can't change",
			"these but you can",
			"check to see if they",
			"are being saved and",
			"restored properly!"
		};
		public byte[] SomeBytes={1,2,3,5,7,11,13,17,19,23,29};
		public bool[] Truth={false,true,true,false,true};
		public string[] Headers={"Type","Name","Age","Master"};
		public int[] Orders={0,1,2,3};
		public int[] Widths={70,50,50,70};
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Jim Hollenhorst
Researcher
United States United States
Ultrapico Website: http://www.ultrapico.com
 
Download Expresso 3.0, the latest version of the award-winning regular expression development tool.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1411023.1 | Last Updated 16 Mar 2003
Article Copyright 2003 by Jim Hollenhorst
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid