Dynamically Form Property Setting (Urgent)

  • Thread starter Thread starter Ahmet
  • Start date Start date
A

Ahmet

Hi all;

I have one application in which I read form names from database to be opened.
I open form with the code below, and call its show method for form to be shown

but before this, I must set MdiChild property to true to make this form child

I can call functions as you can see like (show), how can i set.MdiParent = this property of dynamically loaded form ?
Or I can call a form function dynamically with parameter ?
/*------------------------------------------------------------------------*/

public void OpenForm(string pi_form_dll_name)

{

bool bFindForm = false; Assembly formAsm = null;

try

{

this.Cursor = Cursors.WaitCursor;

formAsm = Assembly.LoadFrom(pi_form_dll_name + ".dll");

Type[] ClassTypes = formAsm.GetTypes();

foreach(Type clsType in ClassTypes)

{

if (clsType.IsSubclassOf(typeof(Form)))

{

object o = System.Activator.CreateInstance(clsType);

MethodInfo mi = clsType.GetMethod("Show"); // here can we invoke property of MdpParent=this instead of invoking method ?

mi.Invoke(o, null); bFindForm = true; break;

}

}


if (bFindForm == false)

{

string sErr = pi_form_dll_name + ".dll does not have " +

"Form-derived class defined";


MessageBox.Show("Form Open Error",sErr);

}

}

catch(System.Exception eSysExc)

{

MessageBox.Show(eSysExc.Message,"Form Open Error");

}

finally

{

this.Cursor = Cursors.Arrow;

}

}

/*------------------------------------------------------------------------*/






helps'll be appreciated..
Ahmet
 
Ahmet

Why don't you cast the object 'o' to Form and work from it that rather than
trying to do everything via reflection on object?

Regards
Lee

Hi all;

I have one application in which I read form names from database to be
opened.
I open form with the code below, and call its show method for form to be
shown

but before this, I must set MdiChild property to true to make this form
child

I can call functions as you can see like (show), how can i set.MdiParent =
this property of dynamically loaded form ?
Or I can call a form function dynamically with parameter ?
/*------------------------------------------------------------------------*/
public void OpenForm(string pi_form_dll_name)
{
bool bFindForm = false; Assembly formAsm = null;
try
{
this.Cursor = Cursors.WaitCursor;
formAsm = Assembly.LoadFrom(pi_form_dll_name + ".dll");
Type[] ClassTypes = formAsm.GetTypes();
foreach(Type clsType in ClassTypes)
{
if (clsType.IsSubclassOf(typeof(Form)))
{
object o = System.Activator.CreateInstance(clsType);
MethodInfo mi = clsType.GetMethod("Show"); // here can we invoke
property of MdpParent=this instead of invoking method ?
mi.Invoke(o, null); bFindForm = true; break;
}
}
if (bFindForm == false)
{
string sErr = pi_form_dll_name + ".dll does not have " +
"Form-derived class defined";
MessageBox.Show("Form Open Error",sErr);
}
}
catch(System.Exception eSysExc)
{
MessageBox.Show(eSysExc.Message,"Form Open Error");
}
finally
{
this.Cursor = Cursors.Arrow;
}
}
/*------------------------------------------------------------------------*/



helps'll be appreciated..
Ahmet
 
Because I read form's dll name from database and I find dll for this form
then dynamically load this form.

I dont want to make

if (dbObj.FormName = "Customer")
fCustomer.Open();
else
else
....
because I have 100 + forms
I call Show Method to show but it must be MdiChild, so I must set MDiParent
of any opening form to this pointer
 
Back
Top