Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hey,

I'm writing a Windows Form Application and I have two projects in the solution. I've added a project reference to reference the two projects to each other. I'm trying to open a form on the other project, but I get the 'Reference to a non-shared member requires an object reference.' error when I try to use this

Launchform.show()

I've already added the Imports Project2 line which gives me access to the classes, but they won't give me access to the forms where I can use Form.Show(), Form.Close, Form.Focus, etc.

Is there any way I can share the forms across the projects?

Thanks for any help :),
Chris
Posted
Comments
[no name] 30-Jun-13 19:47pm    
You might need to share a bit more of your code but have you tried,
Dim l as Launchform = new Launchform()
l.Show()?

1 solution

This problem has nothing to do with "projects". First thing you should understand is that the "project" does not exist during run-time. The project is the artifact which is nothing but the data used to build an assembly. Only assemblies are the players during runtime.

And you did not approach runtime, not even close, as you faced with the simplest problem. Your Launchform.Show() could not compile, because, judging by the error message, Launchform is a type, hopefully derived from System.Windows.Forms.Form and Show is its instance method. And the instance method needs a reference to some instance, not just type. For example, something like this could work:
VB
Dim form As Form = New Launchform()
' ...
form.Show()
Again, it all has nothing to do with the fact you have to different project and more than one assembly in your application. Using multiple assemblies is very natural to .NET and is one of its bases.

What you really need is learning of the very basics of programming and, in particular, OOP. You need to understand type and their instance (object), managed references, value vs reference types, assemblies and modules, basics of projects and their builds, and so on.

—SA
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900