Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling another window form
Message
From
03/03/2004 10:59:41
 
 
To
03/03/2004 10:16:24
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
00882702
Message ID:
00882737
Views:
19
Alan,

I'm assuming that you don't want this new form to be modal. Just another open form, correct? You *could* just open it like this:
MyForm oForm = new MyForm(parm1, parm2);
oForm.Show();
But then that can cause complications later when the main form closes and you're trying to find and close all other open forms. So, we use a FormsHandler class which simply puts the form into a static ArrayList (with .Add(), .Remove() and .Close() static methods). So calling the form would be like this instead:
MyForm oForm = new MyForm(parm1, parm2);
FormsHandler.Add(oForm);
oForm.Show();
And when you close your main form, you can simply call FormsHandler.Close() and it will loop through all the Forms in it's ArrayList and call each one's .Close() method.

The FormsHandler looks something like this:
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
}
Hope that helps,

~~Bonnie
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