如何在C#中运行Windows窗体应用程序和控制台应用程序? [英] How to run windows form application and console application in C#?

查看:109
本文介绍了如何在C#中运行Windows窗体应用程序和控制台应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在c#中的控制台应用程序中运行Windows窗体应用程序,但我不知道该怎么做



我尝试过:



我还没有尝试任何东西

I want to run windows form application in console application in c#, but i didn't know how to do it

What I have tried:

I haven't nothing try anything yet

推荐答案

目前尚不清楚做什么你的意思是运行。



首先,严格来说,没有应用程序分类到控制台和窗口应用程序这样的东西。微软只是以一种误导的方式呈现内容。



所以,你只需要知道如何通过另一个应用程序运行一个应用程序。你需要了解你开始两个不同的处理。您可以使用 System.Diagnostics.Process.Start

Process.Start Method(System.Diagnostics)




现在,关于项目输出类型。使用.NET,这总是一个.NET程序集。



在Visual Studio中以一种非常混乱的方式表达了一个重要的观点。



要显示它,你可以做一件简单的事情:创建一个Forms应用程序或一个WPF应用程序是一种标准方式,比如使用标准/默认项目模板。运行。你会看到一些UI。现在,查看项目Properties,第一个选项卡Application。查看选项O u tput Type。在所有情况下,它都将是Windows应用程序。



现在,您将更改为控制台应用程序,而不是更改其他内容会发生什么?你会期待什么?窗口UI会消失吗?不,不是那样的。用户界面不会改变。除了窗体或窗口......控制台外,只显示应用程序。如果使用对象 System.Console 编写一些控制台输出,它将显示。



为什么会这样?这是因为控制台应用程序实际上意味着显示控制台。而Windows应用程序并不意味着会显示一些窗口化的UI。实际上,它只是意味着不要显示控制台。在上一个实验中,反过来,你可以从控制台应用程序开始,然后添加所需的引用程序集,在入口点方法中创建一个窗口或表单并执行Application.Run(任何一种WPF形式)库)。



基本上或功能上,没有三种输出类型。输出选项可以分为库和应用程序,应用程序有选项显示控制台。 Microsoft决定将所有这些选项分类为三种正式等效的输出类型,而不是解释它的正确含义。而这不仅仅是工作室;如果只使用编译来构建项目,则选项是相同的。微软的人并不关心许多人会感到困惑,因为这对大多数人来说并不重要;如果你真正了解背景,你可以看到它是如何运作的; 2)尝试使用控制台创建一个Windows应用程序,3)尝试创建没有任何窗体或窗口的非控制台应用程序。



但是,我总是喜欢知道。 :-)



-SA
It's not clear what do you mean by this "run in".

First of all, strictly speaking, there is no such thing as classification of applications into "console" and "window" applications. Microsoft just present things in a misleading way.

So, you just need to know how to run one application by another application. You need to understand that you start two different processed. You can use System.Diagnostics.Process.Start:
Process.Start Method (System.Diagnostics).


Now, about project output type. With .NET, this is always a .NET assembly.

There is one important point which is expressed in Visual Studio in a very confusing way.

To reveal it, you can do one simple thing: create a Forms application or a WPF application is some standard way, say, using a standard/default project template. Run it. You will see some UI. Now, look at the project Properties, first tab "Application". Look at the option "Output Type". In all cases, it will be "Windows Application".

Now, what happens of you change it to "Console Application", not changing anything else? What would you expect? Will the windowed UI disappear? No, nothing like that. The UI won't change. Only the application will show, in addition to the form or a window… a console. If you write some console output using the object System.Console, it will be shown.

Why so? this is because "Console Application" really means "Show console". And "Windows Application" does not really mean that some windowed UI will be shown. In reality, it simply means "Don't show the console". Line the in the previous experiment, the other way around, you can start with "Console application", and then add required referenced assemblies, create a window or form in the entry-point method and execute Application.Run (of either Forms of WPF library).

Essentially, or functionally, there are no three output types. The output options can be classified into "Library" and "Application", and the "Application" has option "Show console". Microsoft decided to classify all these option in three formally equivalent output types and not explain what it means properly. And this is not just the studio; if you build projects using just the compile, the options are the same. Microsoft people did not care that many would be confused, because it doesn't matter for most; you can see how it really works if you 1) really understand the background; 2) try to create a windows application with a console, 3) try to create non-console application without any forms or windows.

However, I always prefer to know. :-)

—SA


Refer - 您可以从C#控制台应用程序中执行另一个EXE文件吗? - 堆栈溢出 [ ^ ]
Refer - Can you execute another EXE file from within a C# console application? - Stack Overflow[^]


这篇关于如何在C#中运行Windows窗体应用程序和控制台应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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