Hello
I am trying to create a windows project with an advanced form collection.
What i'm trying to achieve:
a class called "Interfaces" containing all the forms in my project
e.g.
[CODE]
public class Interfaces
{
private static Interfaces uniqueInstance;
private Form1 form1;
private Form2 form2;
public static Interfaces GetInstance()
{
if (uniqueInstance == null)
{
uniqueInstance = new Interfaces();
}
return uniqueInstance;
}//GetInstance
public Form1 Form1
{
get
{
if(form1 == null || form1.IsDisposed)
{
form1 = new Form1();
}
return form1;
{
}
public Form2 Form2
{
get
{
if(form2 == null || form2.IsDisposed)
{
form2 = new Form2();
}
return form2;
{
}
}//class Interfaces
[/CODE]
and when i'd like to open a form, i would use the following code:
[CODE]
Interfaces.GetInstance().Form1.Show();
[/CODE]
This works fine, as long as the form i'm trying to open doesn't have any parameters, however, how can i use the same method for showing my forms when it DOES have parameters?
e.g.
Form1 form = new Form1("tekst",id);
Thanks in advance
Loading
michaelPosted Apr 18, 2008, 12:54 PM
i tried with a set property before, didnt work out however, but your method works great
AlanPosted Apr 18, 2008, 11:14 AM
Well, you could add a 'setter' to the properties. For example:
public Form1 Form1
{
get
{
if(form1 == null || form1.IsDisposed)
{
form1 = new Form1();
}
return form1;
{
set
{
if(form1 == null || form1.IsDisposed)
{
form1 = value;
}
}
}
and then call with:
Interfaces.GetInstance().Form1 = new Form1("tekst",id);
Incidentally, if you're using .NET 2.0 or later, have you noticed the Application.OpenForms property?
http://msdn2.microsoft.com/en-us/library/system.windows.forms.application.openforms.aspx