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 GerviPosted Aug 11, 2009, 7:24 AM
Pay atension -
Master BillaPosted Aug 11, 2009, 6:03 AM
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 GerviPosted Aug 11, 2009, 5:10 AM
Dim cCurrForm As Form = DirectCast(Activator.CreateInstance(Assembly.GetExecutingAssembly.GetType(pForm)), Form)