Two forms in a single archive

  • Thread starter Thread starter Jaime Lucci
  • Start date Start date
J

Jaime Lucci

Hi.

I'm trying to put 2 forms in a single archive. For example:

public class from1
....
end class

public class form2
.....
end class

Both in a sinfle file myfile.vb.

When I'm trying to instance the second form I have a reference error in the
resourse archive. I want to do that becasue I'm writing a class which will
become a .dll with a Splash Form a the Main Form of any aplicattion we
design from now on. The splash is always the same and the main form too. The
main form has a treeview which deffers between the different applications we
design.

If you have another idea to this would be welcome.

Thanks.

Jaime
 
Jaime Lucci said:
I'm trying to put 2 forms in a single archive. For example:

public class from1
...
end class

public class form2
....
end class

Both in a sinfle file myfile.vb.

When I'm trying to instance the second form I have a reference error in
the
resourse archive.

Are you talking about the ResX file?

I strongly suggest to place each form in a separate code file. This will
make editing the forms in the Windows Forms designer easier and prevent
resources from getting screwed up. Note that it's completely irrelevant if
classes are placed in separate code files or in a single code file for the
appearance of the object model. You can still compile both forms into a
single DLL by adding both ".vb" files to the same project.
 
You actually mean a single file, right?

I'm interested as in why you want to even put them in the same file.
But that shouldn't really matter. The compiler lets you place as many
classes as you want in a single file. I've never run into the
reference error that you're talking about. Are you talking about
"Object reference not set to an instance of an object"? If that's the
case, you need to instantiate your objects.

Are you a developer that has moved on to VB .NET from VB 6? You have
to remember that .NET is an object oriented environment and that
everything is an object, including forms.

When you want to display your splash form, you'll have to instantiate
it from your main form and then show it.

Assuming that you're loading the splash form from the main form's load
event, you'll just need to add the following code.

dim f2 as New Form2 'Make note of the New keyword. That instantiates
the object and tells .NET to create it.
f2.Show()

That should do it if you're experiencing the error that I mentioned
above.

I would still advise against creating the two classes in a single file
as it could lead to harder to read code. I would just add a new form
to the project and have two separate files. There's really no need to
have a single file. If you're concerned about how it will appear the
Solution Explorer, you can add a folder, and place classes in that sub
folder. That can help you organize your code. Hope this helps.

Derek Woo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top