D
David McCallum
The object of the code snippet below is to save and restore a form's size
and location. The saveFormSettings() method is called when a form is closing
and restoreFormSettings() is called after InitializeComponent().
The problem is even though the settings appear to be being saved, the
strWidth variable is always null, so the settings are never restore.
Any clues as to what I'm doing wrong?
TIA
David McCallum
private static NameValueCollection appSettings =
ConfigurationManager.AppSettings;
/// <summary>
/// Restore a form's settings
/// </summary>
/// <param name="form">The form to restore</param>
public static void restoreFormSettings(Form form)
{
string strWidth = appSettings.Get(form.Name + "FormWidth");
if (strWidth != null)
{
string strHeight = appSettings.Get(form.Name + "FormHeight");
string strX = appSettings.Get(form.Name + "FormX");
string strY = appSettings.Get(form.Name + "FormY");
form.Size = new Size(Int32.Parse(strWidth), Int32.Parse(strHeight));
form.Location = new Point(Int32.Parse(strX), Int32.Parse(strY));
}
}
/// <summary>
/// Save a form's settings
/// </summary>
/// <param name="form">The form to save</param>
public static void saveFormSettings(Form form)
{
appSettings.Set(form.Name + "FormWidth", form.Size.Width.ToString());
appSettings.Set(form.Name + "FormHeight", form.Size.Height.ToString());
appSettings.Set(form.Name + "FormY", form.Location.Y.ToString());
appSettings.Set(form.Name + "FormX", form.Location.X.ToString());
}
and location. The saveFormSettings() method is called when a form is closing
and restoreFormSettings() is called after InitializeComponent().
The problem is even though the settings appear to be being saved, the
strWidth variable is always null, so the settings are never restore.
Any clues as to what I'm doing wrong?
TIA
David McCallum
private static NameValueCollection appSettings =
ConfigurationManager.AppSettings;
/// <summary>
/// Restore a form's settings
/// </summary>
/// <param name="form">The form to restore</param>
public static void restoreFormSettings(Form form)
{
string strWidth = appSettings.Get(form.Name + "FormWidth");
if (strWidth != null)
{
string strHeight = appSettings.Get(form.Name + "FormHeight");
string strX = appSettings.Get(form.Name + "FormX");
string strY = appSettings.Get(form.Name + "FormY");
form.Size = new Size(Int32.Parse(strWidth), Int32.Parse(strHeight));
form.Location = new Point(Int32.Parse(strX), Int32.Parse(strY));
}
}
/// <summary>
/// Save a form's settings
/// </summary>
/// <param name="form">The form to save</param>
public static void saveFormSettings(Form form)
{
appSettings.Set(form.Name + "FormWidth", form.Size.Width.ToString());
appSettings.Set(form.Name + "FormHeight", form.Size.Height.ToString());
appSettings.Set(form.Name + "FormY", form.Location.Y.ToString());
appSettings.Set(form.Name + "FormX", form.Location.X.ToString());
}