Saving & Loading Application Settings in C#

If your application uses application settings that are the scope of “User”, in C# you will need to add code that will save and load these settings during shutdown and startup (this is automatic when using VB.NET).

In your Main() method of the Program.cs file add the first two lines below to load the settings and setup an event for saving:

  static void Main()
    Application.ApplicationExit +=
      new EventHandler(Application_ApplicationExit);
    Application.Run(new Form1());

Then add this method to save the settings during application shutdown:

static void Application_ApplicationExit(object sender, EventArgs e)

Tip By: David McCarter