Create and display a form based on its Name
Option Strict On
Option Explicit On
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Public Class Form1
Inherits Form
Public Sub New()
Me.Text = "Main Form"
AddHandler Me.Click, AddressOf FormClick
End Sub
Public Sub FormClick(byval sender As Object, byval e As Eventargs)
Dim myType As Type = Type.GetType("Form2")
Dim myForm As Form
Dim newForm As Object = Activator.CreateInstance(myType)
myForm = CType(newForm, Form)
myForm.Show()
End Sub
<STAThread()> _
Shared Sub Main()
Application.Run(New Form1())
End Sub
End Class
Public Class Form2
Inherits Form
Public Sub New()
Me.Text = "Second Form"
End Sub
End Class