Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all

I've got a form name (string) that was read from a database field. I want to take this string and create a form instance and invoke the show/showdialog method on it.

Can anyone help me with this?

 

Thanks in advance :)

Howzit??
  • *Experts*
Posted

I don't understand. Do you mean you want to create a form that is

named whatever the string is? I don't think that's possible, considering

forms don't have Name properties anymore (their names are their

object names; there is no seperate string property like in VB6).

 

You weren't exactly clear about how the string ties in with the form

instance. :confused:

Posted (edited)
Let me clarify: I have a project that contains n amount of Forms. I store the class names (form names e.g. Form1 - nothing to do with the Name property) in a database. From a main form I would like to dynamicaly create a instance of one of these forms, using it's class name, and fire the Show/ShowDialog methods. Edited by Cywizz
Howzit??
Posted

No worries, got the solution... if interested:

//In form1. if you want to create instance of form2 (the same assembly)
Type theObjectType = Type.GetType("YourNamespace.Form2");
Object theObject = Activator.CreateInstance(theObjectType);
//Get the method and invoke it
System.Reflection.MethodInfo m = theObjectType.GetMethod("Show");
m.Invoke(theObject,null); 

Howzit??
Posted

Thanks divil. This would be easier, if I knew the type and method - I also hold the object method in the database (Show or ShowDialog), so I'll need to call a method dynamically.

This project might progress to other data types, not just forms as well

 

Thanks again!

Howzit??

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...