Home All Groups Group Topic Archive Search About

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

Author
6 Apr 2005 7:44 PM
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.

Author
6 Apr 2005 7:59 PM
Herfried K. Wagner [MVP]
"Michael Creager" <mdcrea***@adelphia.net> schrieb:
>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()
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
7 Apr 2005 12:21 AM
Dennis
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.

Show quoteHide quote
"Michael Creager" wrote:

> 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.
>
>
>
>