在一个解决方案中使用两个项目 [英] using two projects in one solution

查看:81
本文介绍了在一个解决方案中使用两个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

希望你做得好。



i需要关于以下问题的帮助。



我有两个不同的Windows项目Collection和Uticare。

i添加了Uticare Proj。收集项目



现在我想要运行应用程序时它会要求运行哪个应用程序(Collection / uticare)。



选择表格上的单选按钮后,它会重定向到该应用程序(Collection / uticare)



是否有可能......?

请回复我。

提前感谢



问候

prajucta

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

推荐答案

拥有多个.NET中的项目解决方案并不罕见;事实上,很多关于CodeProject的文章都有可下载的例子,其中有许多项目在一个'解决方案中。



允许最终用户在运行时选择的一般模式哪个项目打开是:



1.在申请表中(或主项目:您设置为'启动项目的那个)



a。添加对其他项目的引用:



选择主项目中的'引用,单击'添加引用:根据您使用的Visual Studio版本查找选项卡命名为解决方案/项目,并选择其他项目。



b。在主项目的主要表格中:



添加'使用陈述以允许主项目访问其他项目;例如:



使用Project1;

使用Project2;



At这一点你有两个选择如何打开/运行其他项目:



1.使用公开的'其他项目的表单对象来创建一个新的实例它,然后调用'在新实例上显示。



2.使用Process.Start



一个。如果使用Process.Start,您的主表单必须能够访问System.Diagnostics工具:



使用System.Diagnotics;



因此,如果你有一个解决方案:一个主项目,另外两个项目,Project1和Project2,你可能有这样的代码:
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");
    }
}

讨论:



1.使用调用'Show'或'Process的方法。开始:永远不会调用其他项目的Program.cs类中的静态'Main方法:但它必须在那里进行编译。



2如果您使用'显示然后关闭主表单,其他项目表格将自动关闭。



3.如果您使用Process.Start,关闭主表单不会自动关闭您使用Process.Start激活的项目表单。这是因为你已经在他们自己的线程上启动了其他项目。



4.参考文献:



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



流程类(.NET FrameWork 3.0 MSDN): [ ^ ]



5.供将来使用:



使用Process.Start(ProjectName)返回对'Process Class的实例的引用;在上面的代码中,我们不保留该实例。在将来,您可能希望捕获实例引用,因为您可以根据需要使用Kill运算符来关闭实例。

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.


这篇关于在一个解决方案中使用两个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆