Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
hello all.
hope u r doing good.

i need a help regarding following problem.

I have two different windows projects "Collection" and "Uticare".
i have added Uticare Proj. To Collection Proj.

now i want when i ll run application it will ask to run which application (Collection/uticare).

after selecting radio button on form it ll redirect to that application (Collection/uticare)

Is it possible...?
please revert me back.
thanks in advance

regards
prajucta
Posted
Updated 22-Oct-13 19:32pm
v2
Comments
BillWoodruff 23-Oct-13 1:24am    
Is this Windows Forms ? Please tag your question.
Sergey Alexandrovich Kryukov 23-Oct-13 1:39am    
No, you don't add a project to a project. You are adding to projects to solution, and, possibly, reference one assembly by another, and the best was to do it is by using the "Projects" tab. But probably you did not do even that, you created two separate applications. Why?
Why "redirecting"? Usually, it makes no sense. Please understand: different applications are always different processes, which are well isolated to each other and generally not designed for cooperation, unless you use some special mechanism (messaging, IPC, automation, whatever).

Anyway, you did not described the problem, nor did you provide enough information, not even close.
—SA
Prajucta.Chatarjee 23-Oct-13 1:48am    
thanks for your reply sir. i m a beginner so i don't hv more knowledge regarding this. i hv added two proj in one solution. i need both applications in one setup. at application start i want a form for select option. after selecting it ll redirect to specified page (collection/uticare) hope u can understand now. thanks
Sergey Alexandrovich Kryukov 23-Oct-13 2:01am    
Forget about setup, first create a solution. You need to start the question with explanation of your goals, and then to provide all information which might be important...
—SA
Bajirao_ 23-Oct-13 1:44am    
"i have added Uticare Proj. To Collection Proj." ?

Do you mean 2 project in 1 solution?
Or referring a nesting of project.

If you have 2 project in 1 solution then, in case of windows application they will provide you a .exe file. You can add 3rd project in solution. Then add form which accept input and run required .exe file.

using System.Diagnostics;

class Program
{
static void Main()
{
Process.Start("MyProject.exe"); // Enter path of exe file
}
}

Hope it helps..

1 solution

It is not uncommon to have more than one 'Project in a .NET 'Solution; in fact, many articles on CodeProject have downloadable examples which have many Projects in one 'Solution.

The general pattern for allowing the end-user at run-time to select which Project is "opened" is:

1. in the Application Main Form (or, Main Project: the one you have set as the 'Start-Up Project)

a. add a reference to the other Projects:

Select 'References in the Main Project, click 'Add Reference: depending on the version of Visual Studio you use look for a Tab named something like 'Solutions/Projects, and select the other Projects.

b. in the Main Form within the Main Project:

add 'using statements to allow the Main Project access to the other Projects; for example:

using Project1;
using Project2;

At this point you have two choices on how to open/run the other Projects:

1. use the exposed 'Form object of the other Projects to create a new instance of it, and then call 'Show on the new instance.

2. use Process.Start

a. if use Process.Start, your Main Form must have access to the System.Diagnostics facility:

using System.Diagnotics;

So, if you had in one Solution: a Main Project, and two other Projects, Project1, and Project2, you might have code like this:
// other standard 'using statements
using Project1;
using Project2;
using System.Diagnotics;

// for use with 'Show from the Main Form
private Project1.Project1Form proj1Window;
private Project2.Project2Form proj2Window;

// which method to use for activating other Projects ?
private bool IsActivatedWithShow = true;

private void MainForm_Load(object sender, EventArgs e)
{
    // create the instances of Project1 and Project2's Forms
    proj1Window = new Project1.Project1Form();
    proj2Window = new Project2.Project2Form();
}

// 'button1 is a Button on the Main Form
private void button1_Click(object sender, EventArgs e)
{
    if (IsActivatedWithShow)
    {
        // Showing the Form in Project1 without "running" Project1
        // on a separate thread
        proj1Window.Show();
    }
    else
    {
         // using Process.Start
         Process.Start("Project1");
    }
}

// button2 is a Button on the Main Form
private void button2_Click(object sender, EventArgs e)
{
    if (IsActivatedWithShow)
    {
        // Showing the Form in Project2 without "running" Project2
        // on a separate thread
        proj2Window.Show();
    }
    else
    {
         // using Process.Start
         Process.Start("Project2");
    }
}
Discussion:

1. using either the method of calling 'Show, or 'Process.Start: the static 'Main method in the Program.cs Class of both other Projects will never be called: but it must be there for compilation to take place.

2. if you use 'Show then when you close the Main Form, the other Projects' Forms will be closed automatically.

3. if you use Process.Start, closing the Main Form will not automatically close the Project Forms you have activated with Process.Start. This is because you have launched the other Project(s) on their own thread(s).

4. References:

Project.Start (.NET FrameWork 3.0 MSDN): [^]

Process Class (.NET FrameWork 3.0 MSDN): [^]

5. for future use:

Using Process.Start(ProjectName) returns a reference to an instance of the 'Process Class; in the code above, we don't preserve that instance. In the future you may wish to "capture" the instance reference, since you can then, as you need to, use the 'Kill operator to shut-down the instance.
 
Share this answer
 
v2
Comments
Prajucta.Chatarjee 23-Oct-13 7:11am    
thanks a lot.. it worked. :) (Y)
Member 11905957 13-Mar-17 13:27pm    
Hi BillWoodruff, how if in vb.net?? thank you..

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