wdw Posted December 18, 2002 Posted December 18, 2002 I've this code: Dim f As Form, s As String s = "Form1" f = Forms.add(s) f.Show() I've the following problem: vb.net does not recognize Forms.Add Can someone give me the correct code for this? thanks Quote
gomindi Posted December 18, 2002 Posted December 18, 2002 Hope this helps we wnated form 1 to hide and then form 2 to show so this is the code we used: I don't know if it's exactly what you're looking for Me.Hide() Dim F As New Form2() 'we inserted variables that will pass to form2 here. F.Show() sorry if this isn't what you need. thanks! Mindi Quote
*Gurus* divil Posted December 19, 2002 *Gurus* Posted December 19, 2002 There isn't a Forms collection in VB.NET, and I haven't a clue what you're trying to do. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
wdw Posted December 19, 2002 Author Posted December 19, 2002 Ok, I'll explain what I am trying to do: I've have a menu where a user can select a menuitem. if he selects an item, he must go to a specific page. The pagename where he must go to comes from the database. But I cannot get the right code. Hope you've got a good way to do this. greetz Quote
*Experts* Nerseus Posted December 19, 2002 *Experts* Posted December 19, 2002 The name of the form (class) is stored as a string in the database? So if you have a class named frmMain and you have a string with the value "frmMain" you want to instantiate frmMain (the class) from the string value? -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
wdw Posted December 23, 2002 Author Posted December 23, 2002 Exactly, that's what I want to do!!! Quote
*Gurus* divil Posted December 23, 2002 *Gurus* Posted December 23, 2002 That really does seem an awfully odd way of doing things. However, if you really need it it should be possibly through the Assembly class: Dim f As Form f = DirectCast(System.Reflection.Assembly.GetExecutingAssembly().CreateInstance("WindowsApplication1.myForm"), Form) f.Show() Where "WindowsApplication1.myForm" is the full-qualified (i.e. including namespace) name of your form in your project. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
wdw Posted December 23, 2002 Author Posted December 23, 2002 i've tried your code, but this is my result: An unhandled exception of type 'System.NullReferenceException' occurred in application.exe Additional information: Object reference not set to an instance of an object. Additional information from me: The form does exist, I use the correct namespace, I have the destination form in a folder in my solution. I don't get it anymore!!:confused: Quote
*Gurus* divil Posted December 23, 2002 *Gurus* Posted December 23, 2002 I'm sorry, but that is the correct and only way of doing what you need. If you're getting that exception, it means you got the namespace wrong. Right-click on your project and select properties. In the box that says Root Namespace will be the namespace you want. Providing you haven't specified a sub-namespace in your form class (I'm guessing you haven't) then you can just use this with your form name in the code I gave you. If your root namespace is WindowsApplication1, the string you'd pass to CreateInstance is WindowsApplication1.Form1, or whatever the name of your form is. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
wdw Posted December 23, 2002 Author Posted December 23, 2002 Thank you very much, I didn't ad the root namespace to my string, so that was the solution to make it work alright. greetz willem 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.