如何从一个WPF应用程序动态打开/关闭控制台窗口? [英] How to open/close console window dynamically from a wpf application?

查看:1072
本文介绍了如何从一个WPF应用程序动态打开/关闭控制台窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个WPF应用程序,我想发布应用程序的测试版,为我添加了一个名为调试,这将基本上显示/隐藏按钮控制台窗口。
我在控制台上相应的消息出现后,每个事件使这将帮助用户报到,他们正在通过查看控制台上的信息有问题。

I am making a wpf application and i want to release a beta version of the application , for that i am adding a button named "debug" Which will essentially show/hide the console window. I am writing appropriate message on the console after each event occurs so This will help users to report back the problem that they are having by looking at the messages on the console .

很抱歉的故事背景(如果它没有帮助),
我基本上需要知道如何在C#中动态显示/隐藏控制台窗口。

Sorry for the background story (if it's not helpful ) , I essentially need to know how to show/hide console windows dynamically in c# .

推荐答案

你觉得现在我明白这个问题?

Do you think now I understood the question?

[DllImport("Kernel32")]
public static extern void AllocConsole();

[DllImport("Kernel32")]
public static extern void FreeConsole();


private void button1_Click(object sender, EventArgs e)
{
    AllocConsole();
    Console.WriteLine("test");
}

这篇关于如何从一个WPF应用程序动态打开/关闭控制台窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆