• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

Open Forms From Sting

Hi. I have a treeview control in my mdi child form. In treeview control form names listing like this,

About
Help
.....

when the user clicks on "About" then frm_about shows.

How can I bind these to values? I got something in my mind but I dont know how to make it. If I write down the treeview names (userfriendly names) in to the forms text property, Is it possible to open it from there? For example;

Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly
        Dim objForm As Form = asm.CreateInstance(asm.GetName.Name + "." + "frmAbout", True)

        objForm.Show()

this code opens from the names from string. Is there any way to find the form name by serching the form header texts? Maybe I can use the upper code to by binding treeview names to form header text.

Like form userfriendly name: About
form name: frm_about
form header text:  About

Anther question, How can I get the name of the forms as a list, which is currently existing in my application.

Thanks.

0
gokhanoz
Asked:
gokhanoz
1 Solution
 
tolgaongCommented:
use the code below

dim progname as string
CType(Activator.CreateInstance(Type.GetType(progName)), Form)

the variable progname will be directly the class name for the classes inside the same assembly.

If the form is in another form, then the progname will be as follows
Namespace.ClassName, AssemblyName


ex: Suppose you have a Form1 in namespace n1, and the assembly is named a1.
You want to call the form from the assesbly: MainAssembly
you should first add a reference to a1
then set the progname as:

n1.Form1, a1

do not forget to put a space after the comma.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now