B
bg_ie
Hi,
I have my own UserSettings class that I wish to include within my
windows application. To include it at the moment, I do something like
this -
namespace WindowsApplication1
{
static class Program
{
static public UserSettings userSettings = new UserSettings();
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ApplicationExit += OnApplicationExit;
Application.Run(new Form1());
}
static void OnApplicationExit(object sender, EventArgs e)
{
XmlSerializer s = new XmlSerializer(typeof(UserSettings));
TextWriter w = new StreamWriter(@"c:\settings.xml");
s.Serialize(w, userSettings);
w.Close();
}
}
}
But to access its members from within Form1 I have to do the following
-
WindowsApplication1.Program.userSettings.Version = "P-100928"
This works fine, but it doesn't feel like a good approach.
I declared userSettings within Program because I need to serialise it
on program exit, as shown above.
Any suggestions as to how I might do this better?
Thanks,
Barry.
I have my own UserSettings class that I wish to include within my
windows application. To include it at the moment, I do something like
this -
namespace WindowsApplication1
{
static class Program
{
static public UserSettings userSettings = new UserSettings();
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ApplicationExit += OnApplicationExit;
Application.Run(new Form1());
}
static void OnApplicationExit(object sender, EventArgs e)
{
XmlSerializer s = new XmlSerializer(typeof(UserSettings));
TextWriter w = new StreamWriter(@"c:\settings.xml");
s.Serialize(w, userSettings);
w.Close();
}
}
}
But to access its members from within Form1 I have to do the following
-
WindowsApplication1.Program.userSettings.Version = "P-100928"
This works fine, but it doesn't feel like a good approach.
I declared userSettings within Program because I need to serialise it
on program exit, as shown above.
Any suggestions as to how I might do this better?
Thanks,
Barry.