Open Existing form from String

BrentP

New member
Joined
Nov 5, 2008
Messages
2
Programming Experience
5-10
I am passing a string value to my application with the name of an unopened form, and I need to use that string name to open up the corresponding form.


Is there any way to do that?
 
Last edited:
Something like this.. using a bit of reflection.

VB.NET:
Imports System.Reflection

Dim frm As Form = DirectCast(Activator.CreateInstance(Type.GetType("yourApplication.someFormName") ), Form)
frm.Show()
 
Much Appreciated

Thank You. I had scoured the Internet, but was unable to find any solution without a direct reference to the existing form.
 
hhmmm... This has got me thinking,

Would this work in a similar way with any object?

I have several Textboxes and ComboBoxes that are created/destroyed at runtime and named txt1, txt2 .... txtn. At the moment, whenever I need to use a control, I use:

VB.NET:
For Each ctrl in me.Controls
   If ctrl.Name = <String> Then
      'Whatever
   end if
next

The above could come in very very handy
 
Rod said:
whenever I need to use a control, I use:
me.Controls("the name") give you the control, or Me.Controls.Find("the name", True) to search all child containers. Reflection is useful to know, but there could be better alternatives.
 
Back
Top