-2
我有一个C#程序,目前我运行2个窗口,第一个是窗体窗口,第二个是用于调试的控制台窗口。如何从Windows窗体应用程序在C#中关闭控制台窗口?
创建accoeding控制台窗口如下:
Create a Windows Form project... Then: Project Properties -> Application -> Output Type -> Console Application
我怎样才能通过按键关闭控制台窗口从表单点击?
编辑:
我试着做以下,但只是形式窗口..
private void button1_Click(object sender, EventArgs e)
{
System.Environment.Exit(0);
}
编辑2这是接近: 下面的代码只执行前前面的代码工作。
using (process = new Process())
{
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
process.StartInfo.WorkingDirectory = @"C:\";
process.StartInfo.FileName = Path.Combine(Environment.SystemDirectory, "cmd.exe");
// Redirects the standard input so that commands can be sent to the shell.
process.StartInfo.RedirectStandardInput = true;
// Runs the specified command and exits the shell immediately.
//process.StartInfo.Arguments = @"/c ""dir""";
process.OutputDataReceived += ProcessOutputDataHandler;
process.ErrorDataReceived += ProcessErrorDataHandler;
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
// Send a directory command and an exit command to the shell
process.StandardInput.WriteLine("cd " + currentPath);
process.StandardInput.WriteLine("ibt -mic");
}
你有什么尝试,你有任何代码从这个尝试?我们不会为您编写从头开始的代码,但如果您向我们展示您迄今为止的内容,则您更有可能得到回复。 – user2366842
请参阅编辑 –
您发布的代码应该可以工作,它适用于我。你确定这是正在执行? – null