Hi,
I have the following situation, can anybody help me in that?
Following is a "pseudo" code of what I want to do in VB or C# using VS.NET 2005:
In my main form I have the following
'Code Begins
Dim vCurrentForm As Form
Private Sub CallCurrentForm (ByVal pForm as String)
If vCurrentForm Is Nothing OrElse vCurrentForm.IsDisposed Then
vCurrentForm = <# New pForm #>
vCurrentForm.MdiParent = Me
ElseIf Not TypeOf vCurrentForm Is <# pForm #> Then
vCurrentForm.Close()
vCurrentForm = <# New pForm #>
vCurrentForm.MdiParent = Me
End If
vCurrentForm.Show()
End Sub
'Code Ends
Where I am calling 'CallCurrentForm' everywhere in my menu just by passing the proper form name as a string
example: CallCurrentForm("AddNewAccount")
My problem is how to do the code between <# ... #>
Thanks

Danatas GerviRank #4,152 · 361 reputationPosted Aug 11, 2009, 1:10 AM EDT
Dim cCurrForm As Form = DirectCast(Activator.CreateInstance(Assembly.GetExecutingAssembly.GetType(pForm)), Form)
Master BillaRank #2,229 · 630 reputationPosted Aug 11, 2009, 2:03 AM EDT
Here code for you
public static Object GetReferenceFromClass(string AssemblyName, string ClassName, object[] args)
{
Assembly assembly = Assembly.LoadFrom(AssemblyName);
foreach (Type type in assembly.GetTypes())
{
if (type.IsClass == true)
{
if (type.FullName.EndsWith("." + ClassName))
{
ConstructorInfo[] con = type.GetConstructors();
foreach (ConstructorInfo construtor in con)
{
if (construtor.GetParameters().Length == args.Length)
{
return construtor.Invoke(args);
}
}
}
}
}
throw (new System.Exception("could not create instanace----->" + ClassName));
}
Thank you
Danatas GerviRank #4,152 · 361 reputationPosted Aug 11, 2009, 3:24 AM EDT
Pay atension -
cCurrForm - must be base class for pForm and previos form. In common case, it may be System.Windows.Form. But if you want more, than simple showing, you should or use a casting to needed form, or use base class or interface.