Click here to Skip to main content
15,881,872 members
Please Sign up or sign in to vote.
1.24/5 (4 votes)
See more:
How to open a new form from another project form button click event
Posted

1 solution

There is no such thing as "open a form". (Yes, terminology is misleading. There is "close", but none of the form methods "opens" it. You need to hold you fantasy and not assume the everything in API is named according to your intuitive understanding of things; it can betray your.) You can create an instance of the form and show it, that's all:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.show.aspx[^],
http://msdn.microsoft.com/en-us/library/szcefbbd.aspx[^] (rarely makes sense),
http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx[^],
http://msdn.microsoft.com/en-us/library/w61zzfwe.aspx[^].

The situation with your understanding of "projects" is even worse. A project is actually some data set instructing compiler (and, sometimes, some other tools) to build an assembly out of source code. There are no "projects" during runtime, but the central notion of the CLR and the main unit is assembly. With Visual Studio, each project creates a single assembly consisting of one single executable module. (Compilers allow to create an assembly made of one or more of modules, but Visual Studio does not support it by default.) One assembly can reference others; and the referenced assembly serves as a shared class library unit to the assembly referencing it. Basically, that's all.

When an application is built, it can be an assembly referencing other assemblies, and each of referenced assemblies can reference some other ones. It's nearly irrelevant, what classes are written in what assemblies; the cross-assembly visibility is controlled by public and protected access modifiers, that's all. You can write a Form class in one assembly, and create a form instance of this time in another one, if you reference the first assembly. There is no need to ask how. In exact same way as in the case of a single assembly.

—SA
 
Share this answer
 
Comments
Mahesh_Bhosale 15-Apr-13 3:21am    
i had created one user control named as toolbar that contain one search button. I want to use this user control in my project.I just drag and drop this control in any form of my project. When user click on the search button then it must be show search form of project. i can't understand how to do this, if you know then please help me.
Thank you.
Sergey Alexandrovich Kryukov 15-Apr-13 3:32am    
This is so simple that I cannot imagine what you are missing. If you explain what you don't know, I'll try to qualify.

Besides, I highly recommend to use only one window. Look at Visual Studio: all API in one window. Look at many other high-quality UI.
—SA
Mahesh_Bhosale 15-Apr-13 3:45am    
I am creating one user control named as toolbar.dll it contain search button. now in VS2010 toolbax i adding new item toolbar.dll, now i just drag and drop this user control named as toolbar into form. so how to show the frmSearch form of my project when user click on search button.
Sergey Alexandrovich Kryukov 15-Apr-13 3:48am    

mySearchButton.Click += (sender, eventArgs) => {
Form myForm = new MySearchForm();
myForm.Show();
}


Was there anything you did not know?
—SA
Mahesh_Bhosale 15-Apr-13 4:37am    
its give error : The type or namespace name 'frmsearch' could not be found

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