我想在 Winform 中嵌入一个控制台窗口。有什么办法吗?
最佳答案
你需要做的就是调用windows API函数AllocConsloe然后使用普通的控制台类这里是表单代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace waTest
{
public partial class Form1 : Form
{
[DllImport("Kernel32.dll")]
static extern Boolean AllocConsole( );
public Form1( )
{
InitializeComponent();
}
private void Form1_Load( object sender, EventArgs e )
{
if ( !AllocConsole() )
MessageBox.Show("Failed");
Console.WriteLine("test");
string input = Console.ReadLine();
MessageBox.Show(input);
}
}
}
关于c# - 如何在 Winforms 中包含控制台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3917202/