Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

Posted

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

  • *Experts*
Posted

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

"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
  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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:

  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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

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...