hazejean Posted August 8, 2003 Posted August 8, 2003 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 Quote
*Experts* Bucky Posted August 8, 2003 *Experts* Posted August 8, 2003 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 Quote "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* Volte Posted August 8, 2003 *Experts* Posted August 8, 2003 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 IfNothing 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.