c# - 如何在 Winforms 中包含控制台?

标签 c# winforms console

我想在 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/

相关文章:

c# - 发送邮件到数据库列表

c# - 在 SortedDictionary 中查找最接近的值

c# - 同时选择和编辑数据的解决方案

.net - 网络浏览器控制窃取快捷方式

c# - 覆盖列表框中的默认键绑定(bind)

c# - 奇怪的 RichTextBox 行为

c# - 如何使用 SharpSSH 执行提示额外输入的 linux 命令?

linux - 什么是适用于 Linux 的内存高效文本查看器?

javascript - 如何在 spidermonkey JavaScript 中获取控制台输入?

c# - 从存储过程返回多个表