Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Application object
Message
From
06/10/2005 10:04:49
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01056217
Message ID:
01056744
Views:
23
Pete,

Cetin makes the case for using static DataSets, and in fact, that is one thing I would suggest as well. Another option, which is good to use anyway for other things, is to use a FormsHandler (which also utlizes static properties and methods).
using System;
using System.Collections;
using System.Windows.Forms;

namespace MyAppClasses
{
	public class FormsHandler
	{
		#region Declarations
		private static ArrayList list = new ArrayList();
		#endregion

		#region Methods
		public static int Add(object o)
		{
			return list.Add(o);
		}
		public static void Remove(object o)
		{
			list.Remove(o);
		}
		public static bool Close()
		{
			int nCount = list.Count;
			while (list.Count > 0)
			{
				((Form)list[0]).Close();
				if (list.Count == nCount)
					return false;
				else
					nCount = list.Count;
			}

			return true;
		}
		#endregion

		#region Properties
		public static ArrayList List
		{
			get {return list;}
		}
		#endregion
	}
}
If the first form that you loaded in your application was this special form, then it would always be the first form in your ArrayList and would be easily accessible from anywhere in the app as FormsHandler.List[0].

A FormsHandler is a good idea anyway, because it allows you to easily close all Forms that remain open when the entire application closes. I know you weren't specifically asking about this, but I thought I'd throw it in anyway since it can be useful.

Whenever you open a form, no matter where you open it from, all you do is add it to the ArrayList, like this:
Form oForm = new MyForm();
FormsHandler.Add(oForm);
oForm.Show();
When you close your Main Form, you want all other's to Close (but to execute their own Closing methods) ... do it like this:
// This is a menu item that exits the application

private void menuItem4_Click(object sender, System.EventArgs e)
{
	System.ComponentModel.CancelEventArgs ee = new CancelEventArgs();
	this.ClosingHandler(sender, ee);
}

// This is the ClosingHandler that will execute normally if you close the app
// by clicking on the "X"

private void ClosingHandler(object sender, System.ComponentModel.CancelEventArgs e)
{
	if (!FormsHandler.Close())
		e.Cancel = true;
	else
		Application.Exit();
}
~~Bonnie



>Hello Bonny, maybe I didn't make myself clear enough, the form I refer to takes quite a long time to gather data from various sources so !!!, what I would like to do is: load the form at the app startup and hide it, then pop it up from one of several forms that use it, thanks for your time
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform