How to make a function with a string as parameter and a Form as return type?

  • Thread starter Thread starter Mobile Boy 36
  • Start date Start date
M

Mobile Boy 36

How do you make a function with a formname as stringparameter that returns a
form? Has someone an idea.
 
public Form CreateForm(string formName) {
Form newForm = null;

try {
newForm = new Form();
newForm.Text = formName;

return newForm;
} catch (Exception ex) {

}

}
 
The thing mobile boy 36 means is how to instantiate an object from a
class with a given name. For example: MyForm is the class. In a
Function he wants to write some thing like: Form a =
getFormByName("MyForm")

I also want to know if this is possible somehow.

Greetz

Jens
 
Chris,

Do you have a Vb.net code snippet using reflection ?
It 's not so clear to me what I have to pass to the typename parameter. This
is my code:

Private Shared Function GetFormByName(ByVal FormName As String) As Form
return Activator.CreateInstance(Type.GetType(FormName, True, True))
End Function

What is wrong with it ? I get the error "System.NotSupportedException"
Does the compact framework support this ?
 
Back
Top