简体   繁体   English

在Windows窗体项目中添加和使用控制台应用程序

[英]Adding and using a console application to a windows form project

I have a windows form application that picks a bunch of random numbers and then displays them. 我有一个Windows窗体应用程序,该程序会选择一堆随机数,然后显示它们。 I have edited the 'Matrix Effect' console application to serve as a kind of animation for picking the numbers. 我已经编辑了“矩阵效果”控制台应用程序,以作为一种选择数字的动画。 I have added the console application to my random number picking project but how do I now use it? 我已经将控制台应用程序添加到我的随机号码选择项目中,但是现在如何使用它呢?

Instead of using textbox.text you have to get input as console.readline and to display some message you have to write console.writeline . 代替使用textbox.text,您必须将输入作为console.readline并显示一些消息,您必须编写console.writeline。 This is simple thing which is different in console application otherwise everything else is same and logics also don't need to be changed :) 这很简单,在控制台应用程序中是不同的,否则其他所有内容都是相同的,并且逻辑也不需要更改:)

using System.Runtime.InteropServices;

private void Form1_Load(object sender, EventArgs e) 
{ 
    AllocConsole(); 
} 

[DllImport("kernel32.dll", SetLastError = true)] 
[return: MarshalAs(UnmanagedType.Bool)] 
static extern bool AllocConsole(); 

I think so this should work if yes then please rate the answer :) 我认为这应该可以,如果可以,请给答案打分:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM