复制首部
- 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();释放掉
- }
- }
- }
复制尾部
WinForm启动控制台
本文介绍了一种在Windows窗体应用程序(WinForm)中启动控制台的方法,并提供了使用C#语言实现的具体代码示例。通过调用Kernel32.dll中的API函数AllocConsole(), 可以在WinForm应用运行时显示控制台窗口。
5035

被折叠的 条评论
为什么被折叠?



