By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

Create form based on string?

P: n/a
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

?
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

"Mike" <mi*******@nospam.msn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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

?

Nov 20 '05 #2

P: n/a
* "Mike" <mi*******@nospam.msn.com> scripsit:
Is it possible to create and display a form based on a string variable that
will be set at run-time?


'Activator.CreateInstance':

<http://groups.google.com/groups?selm=bqns3k%2424ghqf%242%40ID-208219.news.uni-berlin.de>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

P: n/a
One more thing... the code I sent you so to use a type..

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

-CJ
"Mike" <mi*******@nospam.msn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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

?

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.