tags:

views:

187

answers:

1

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???
+5  A: 

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

    }
Ash
Thank you :) Very interesting method
nCdy
Glad to help. Of course this makes it look like a normal Windows Forms app, so you're probably best using Windows Forms unless you *really* need the console window.
Ash
Win App is bugged on Nemerle current build >_<
nCdy
You should use `GetConsoleWindow` and not `FindWindow` for this. http://msdn.microsoft.com/en-us/library/ms683175(VS.85).aspx
Ben Voigt