VBN2002 - Programmatically creating a form using a string value as name

  • Thread starter Thread starter Michael Creager
  • Start date Start date
M

Michael Creager

I am using VB NET 2002. How can I programmatically create a new windows
form using the value of a string variable as the name of the new form?

Public FrmName As String = "MDIChildFrm1"
Public %FrmName% as new Form

Does not work.
I cannot find any information on this anywhere. Please help! Thank You.
 
Michael Creager said:
I am using VB NET 2002. How can I programmatically create a new windows
form using the value of a string variable as the name of the new form?

Public FrmName As String = "MDIChildFrm1"
Public %FrmName% as new Form

You cannot change a variable's name at runtime.

If the type of the form is variable, take a look at the code below:

\\\
Imports System.Reflection
..
..
..
Dim frm As Form = _
DirectCast( _
Activator.CreateInstance( _
Type.GetType("MyApplication.SampleForm") _
), _
Form _
)
frm.Show()
///
 
If you want a new form and name it something then;

dim frm as new Form
Form.Name = "nameofyournewform"

If you want to load an existing form using it's name, then do what Herfried
posted.
 
Back
Top