意外的收获——在WinForm中启动控制台
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- namespace 在WinForm中启动控制台
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- [DllImport("Kernel32.dll")]
- static extern bool AllocConsole();
- [DllImport("Kernel32.dll")]
- static extern bool FreeConsole();
- private void button1_Click(object sender, EventArgs e)
- {
- AllocConsole();
- Console.WriteLine("hello");
- //FreeConsole();释放掉
- }
- }
- }
原来一直想找都没有,居然今天在一个叫什么"狂热代码"的家伙那里偷看到了这个.