How to hide console after creating form in console application

故事扮演 提交于 2019-12-07 17:43:38

问题


I want to hide my console after creating a from in my console application. And then show it again after closing form :) or somewhere when I want ...

Console.Hide???
Application.Run(nForm());
Console.Show???

回答1:


I think you'll need to delve into the FindWindow and ShowWindow API calls. For example:

    [DllImport("user32.dll")]
    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);


    [DllImport("user32.dll")]
    public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

    static void Main(string[] args)
    {
        Console.Title = "ConsoleApplication1";

        IntPtr h=FindWindow(null, "ConsoleApplication1");

        ShowWindow(h, 0); // 0 = hide

        Form f = new Form();

        f.ShowDialog();

        ShowWindow(h, 1); // 1 = show

    }


来源:https://stackoverflow.com/questions/2160338/how-to-hide-console-after-creating-form-in-console-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!