开发者

How to hide console after creating form in console application

开发者 https://www.devze.com 2022-12-19 00:18 出处:网络
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 ...

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???
Applicati开发者_C百科on.Run(nForm());
Console.Show???


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

    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号