c#中winform主程序中打开控制台程序,关掉控制台主程序如何才能不退出! 50
winform程序:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usin...
winform程序:
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
[DllImport("kernel32.dll")]
public static extern bool AllocConsole();
[DllImport("kernel32.dll")]
public static extern bool FreeConsole();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
AllocConsole();
Console.Title = "测试标题~";
Console.WriteLine("jjj");
Console.WriteLine("hhhhh");
for (int i = 1; i < 10; i++)
{
Console.WriteLine("输出测试{0}", i);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
希望在关闭控制台后,主程序不关闭。
就是说:我点击控制台右上的关闭按钮,控制台退出,winform不退出! 展开
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
[DllImport("kernel32.dll")]
public static extern bool AllocConsole();
[DllImport("kernel32.dll")]
public static extern bool FreeConsole();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
AllocConsole();
Console.Title = "测试标题~";
Console.WriteLine("jjj");
Console.WriteLine("hhhhh");
for (int i = 1; i < 10; i++)
{
Console.WriteLine("输出测试{0}", i);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
希望在关闭控制台后,主程序不关闭。
就是说:我点击控制台右上的关闭按钮,控制台退出,winform不退出! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询