Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Adding new features to multiple Forms classes
Message
De
10/11/2006 11:38:47
James Hansen
Canyon Country Consulting
Flagstaff, Arizona, États-Unis
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
Adding new features to multiple Forms classes
Divers
Thread ID:
01168767
Message ID:
01168767
Vues:
50
My clients are used to certain features of my VFP applications, such as saving form positions and sizes, that are not supported natively by the MM or .Net frameworks. So I wanted to add these features to several of the form classes provided by MM. This was not as easy as in my VFP CodeBook 6 framework (for good reasons) which had an "I" layer that allowed me to put custom changes in the base form that would be propogated to all forms derived from the base form.

I could not see how to accomplish this in MM without subclassing multiple forms to add the desired features, but I wanted to duplicate as little code as possible in each subclass.

The solution I came up with involves creating an interface, a custom object to implement the changes, and then subclassing the appropriate forms in MM to add the interface and object. I have implemented and tested this and it seems to work well so far, but I present the idea here for people to throw rocks at in case I am missing something. I am (hopefully) about to embark on a large application for a client and would rather start out on the right track.

Basically, the interface is as follows:
	public interface cccFormExtensionInterface
	{
		cccFormExtensions FormExtensions{ get; set; }
	}
I then defined an object thusly (abreviated here):
	public class cccFormExtensions
	{
		//private System.Configuration.ApplicationSettingsBase _settings;
		private Settings FormSettings = new Settings();
		private mmBaseForm ParentForm;
		
		//public cccFormExtensions( mmBaseForm parentForm,  System.Configuration.ApplicationSettingsBase s )
		public cccFormExtensions(mmBaseForm parentForm)
		{
			ParentForm = parentForm;
			this.OnLoad();
		}
		
		private Settings appSettings
		{
			get { return FormSettings; }
			set { }
		}
		
		public void OnLoad()
		{
			FormSettings.SettingsKey = ParentForm.Name;
			
			if (! FormSettings.WindowSize.IsEmpty)
			{
				ParentForm.Size = FormSettings.WindowSize;
			};
			
			ParentForm.Location = FormSettings.WindowLocation;
			ParentForm.WindowState = FormSettings.WindowState;
		}
		
		public void OnClosing()
		{
			FormSettings.WindowState = ParentForm.WindowState;
			ParentForm.WindowState = FormWindowState.Normal;
			FormSettings.WindowLocation = ParentForm.Location;
			FormSettings.WindowSize = ParentForm.Size;
			
			FormSettings.Save();
		}
	}
Finally for each MM form that I wanted to add these feature to, I created a subclass such as:
	public partial class cccBusinessForm : mmBusinessForm, cccFormExtensionInterface
	{
		private cccFormExtensions _FormExtensions;
		public cccFormExtensions FormExtensions
		{
			get { return _FormExtensions; }
			set { _FormExtensions = value; }
		}

		/// <summary>
		/// Constructor
		/// </summary>
		public cccBusinessForm()
		{
			InitializeComponent();
		}

		private void cccBusinessForm_Load(object sender, EventArgs e)
		{
			FormExtensions = new cccFormExtensions(this);
		}

		private void cccBusinessForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			FormExtensions.OnClosing();
		}
	}
Well, there it is. Is there a better/easier way to accomplish this that I'm not seeing? Am I overlooking some pitfall?

TIA for your consideration.

...Jim
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform