Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a situation where I need to open other subform sfrom the currect form.

The number of sub forms and form names will be passed to current form via a text file.

 

Example Form1 reads a text file containing subform names separated by semi-colons

 

example: forma;form123;formx

all three need to be diplayed at once

  • *Experts*
Posted

How about a select case statement? Loop through each item in

the text file and show the appropriate forms.

 

' Add a beginning loop here
Dim frm As Form

Select Case formName ' formName = the form to show's name
 Case "forma"
   frm = New forma()

 Case "form123"
   frm = New form123()

 ' etc.
End Select

If Not frm Is Nothing Then frm.Show()
' Close the loop here

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

  • *Experts*
Posted
Here's some sample code I whipped up to do it from a string.
        Dim fname As String = "TestProj.Form2" 'The name must be fully qualified (i.e., with the namespace)
       Dim formType As Type = Type.GetType(fname)
       Dim f As Form

       If Not formType Is Nothing Then
           f = formType.InvokeMember(Nothing, Reflection.BindingFlags.CreateInstance, Type.DefaultBinder, formType, Nothing)

           f.Text = "My New Form"
           f.Show()
       End If

Nothing fancy; it just uses the awesome power of the System.Type class to find the Form's base type given the string, and then it uses the base type to create an instance of the form and show it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...