|
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
// Part of RJConfig V1.3
namespace RJConfig {
/// <remarks>
/// A baseclass for a Form that automatically loads and restores the the forms size, position and state to
/// and from the configuration file using the CfgVarWindowPos class.
/// </remarks>
public class FormPosSave:Form {
/// <summary>
/// Name of the section where the variables will be stored in the config file.
/// Set this to an appropriate Section name in the derived class constructor.
/// The Section can be shared with other settings for the form.
/// </summary>
protected string mSectionName=null;
/// <summary>
/// The config variable for the position, size and state of the form.
/// </summary>
protected CfgVarWindowPos cfgVarPos;
/// <summary>
/// Public parameterless constructor.
/// Adds events for form loaded and closed.
/// </summary>
public FormPosSave()
{
Load+=new EventHandler(RJFormPosSave_Load);
Closed+=new EventHandler(RJFormPosSave_Closed);
}
/// <summary>
/// The form load event which restores the form position, size and state to the last saved (or default).
/// The section name must have been set before this point.
/// </summary>
/// <param name="Sender">The Form object.</param>
/// <param name="e">Arguments for this event.</param>
private void RJFormPosSave_Load(object Sender, EventArgs e)
{
if (!string.IsNullOrEmpty(mSectionName)) {
cfgVarPos = new CfgVarWindowPos(Config.AppVarInst, mSectionName, this);
// This constructor also changes the forms position, size and state.
}
}
/// <summary>
/// The form close event which saves the current form position, size and state to the config variables.
/// The variables are also transferd to the file config object but not actually saved to file yet.
/// </summary>
/// <param name="Sender"></param>
/// <param name="e"></param>
private void RJFormPosSave_Closed(object Sender, EventArgs e)
{
if (cfgVarPos != null) {
cfgVarPos.SetCfg(this);
Config.AppVarInst.Save(cfgVarPos.xpos.SectionName);
}
}
}
}
|
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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.