控制台到Windows窗体 [英] Console to windows form..

查看:127
本文介绍了控制台到Windows窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经在控制台应用程序中创建了一个简单程序,结果可以像
一样正确打印
名称:abc ...
状态:稳定...

现在我设计了一个带有按钮和文本框的Windows窗体.我需要的是,当我单击该按钮时,控制台应用程序中的结果应显示在窗口窗体应用程序的文本框中. ..你能告诉我该怎么做吗?

谢谢,

解决方案

您可以做的是从WinForms代码中启动控制台应用程序,并将控制台的标准输出重定向到可以在WinForms应用程序中读取的流.

在这里看一下代码示例:

http://msdn.microsoft.com/en-us/library/system. diagnostics.processstartinfo.useshellexecute.aspx [ ^ ]


使用Console.Out 我的提示 [ ^ ]很有用.它是通过另一种方式来实现的(附加了带有控制台的WinForm),但是如果您阅读注释,您也会看到它的另一种方式.

hi,

I have created a simple program in a console application and the result is printing correctly like

Name:abc...
Status:stable...

now i designed a windows form with a button and a text box.What i need is,when i click on the button the results in my console application should be displayed in the text box in the window form application.Is that possible?If yes..could you tell me how to do that?

thanks,

解决方案

What you can do is start the console application from your WinForms code and redirect the standard output of the console to a stream you can read within the WinForms app.

Take a look at the code example here:

http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.useshellexecute.aspx[^]


use Console.Out Link[^] property to send the output from console to a text file, then read the values from the text and show it on the textbox.


In addition to the responses you''ve already had, if you''re wanting to combine Forms and Console then you may find my tip[^] useful. It does it the other way around (WinForm with Console attached) but if you read the comments you''ll see it can be the other way too.


这篇关于控制台到Windows窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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