Create form based on string?

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Is it possible to create and display a form based on a string variable that
will be set at run-time?

In other words, instead of declaring a variable as a user-defined form
class:

Dim MyForm as New frmMyForm

is it possible to do something like

Dim sClassName as String
Dim MyForm as Form

sClassName = "frmMyForm"
MyForm = New sClassName

?
 
Public Sub LoadForm(ByVal formType As Type, ByVal fParent As Form, Optional
ByVal Singleton As Boolean = True, Optional ByVal Modal As Boolean = False)

Dim cThread As System.Threading.Thread

Dim cTPool As System.Threading.ThreadPool

Dim tForm As System.Windows.Forms.Form

Try

tForm = FormAlreadyExists(fParent, formType)

If (tForm Is Nothing) Then

tForm = Activator.CreateInstance(formType)

If (fParent.IsMdiContainer) Then

tForm.MdiParent = fParent

End If

Else

If (Singleton) Then

tForm.Focus()

Else

tForm = Activator.CreateInstance(formType)

If (fParent.IsMdiContainer) Then

tForm.MdiParent = fParent

End If

End If

End If

If (Modal) Then

tForm.ShowDialog(fParent)

Else

tForm.Show()

End If

Catch ex As Exception

End Try

End Sub
 
One more thing... the code I sent you so to use a type..

you can modify that with Type.GetType("myFormType")

-CJ
 
Back
Top