如何从控制台应用程序中弹出窗口.

如何从控制台应用程序中弹出窗口.

问题描述:

我有一个几乎完成的程序,它被编写为C#控制台应用程序.我这样做是因为该程序可以处理很多目录,并且我最喜欢编写控制台应用程序.

我需要的是一种从控制台应用程序启动弹出式表单的方法.表单除了显示控制台应用程序生成的某些图形外,不需要执行任何其他操作.

我看过其他人通过将他们的整个项目转换为Windows窗体应用程序来处理此问题. 我真的不想这么做,因为我需要的只是一个带有显示图形的弹出窗口.

这有可能吗?有人可以解释如何开始使用它,也可以指向说明我的文章的方向.

谢谢
Mike.

I have a program that is nearly completed and written as a C# Console application. I do this because this program works with directories a lot and I am most comfortable writing console applications.

What I need is a way to have a popup form launched from my console application. The form doesnt need to do anything other than display some graphics generated by the console app.

I have looked at other people handel this problem by converting their entire project to a windows form application. I really dont want to do this as all i need a form for is a popup window with a graph displayed on it.

Is this even possible? And can someone either explain how to get this started or point me in the direction of an article that explains this.

Thank You,
Mike.

除非最终运行,否则什么都行不通 System.Windows.Forms.Application.RunSystem.Windows.Forms.Form.ShowDialog [结束编辑] .

这是执行Forms应用程序的主循环的地方.这就是我无论如何都将称为Forms应用程序的东西.无需争论术语;我刚刚告诉你的事情的本质.

让我告诉您,您的我不想要"需要一些您没有提供的动力. Forms应用程序没有任何问题.并且可以根据需要保留控制台代码,因此从任何实际角度来看,您都不会有任何问题.

现在,不要被术语控制台应用程序"作为应用程序类型所混淆.它不能替代"Windows应用程序".简而言之,"Windows应用程序"只是说:隐藏控制台",仅此而已.如果甚至不必具有Window或Form(!).就是说,使它成为一个控制台应用程序",但是带有表单.一种实用的方法是:1)创建一个新的Forms应用程序; 2)将应用程序类型更改为控制台应用程序";尝试一下:它将作为Forms应用程序运行,但会显示一个控制台; 3)将控制台代码移至应用程序.

完成此操作后,您可以修改入口点方法(通常为"Main")以从控制台代码开始,稍后在表单上或在某些条件下或以您喜欢的任何方式运行System.Windows.Forms.Application.Run(Form).

这样,您就可以同时使用控制台"和表单"应用程序,而不会遇到任何问题.

—SA
Nothing will work unless you eventually run System.Windows.Forms.Application.Run or, alternatively, System.Windows.Forms.Form.ShowDialog [END EDIT].

This is where the main cycle of a Forms application is executed; and this is something which I would call Forms application anyway. No need to argue over terminology; what I just told you the essence of thing.

Let me tell you that your "I don''t want" needs some motivation which you did not provide. There is nothing wrong with Forms application; and you can keep your console code if you want, so from any practical point of view, you won''t have any problem.

Now, don''t be confused by the term "Console Application" as the application type. It is not alternative to "Windows Application". Simply put, "Windows Application" simply says: "hide the console", nothing else. If does not even have to have a Window or a Form (!). That said, make it a "Console Application", but with the forms. One practical way of doing it is this: 1) create a new Forms application; 2) change application type to "Console Application"; try it: it will run as a Forms application but will show a console; 3) move you console code to the application.

After your do it, you can modify your entry point method (which is usually "Main") to start with Console code, run System.Windows.Forms.Application.Run(Form) with you form later or on some condition, or whatever you like.

This way, you have a mixture of Console and Forms application, and no problems.

—SA


您需要引用System.Windows.Forms.dll,然后可以创建Form 对象并向其中添加必要的控件.
You would need to reference the System.Windows.Forms.dll and you can create a Form object and add the necessary controls to it.