Maximizing console window - C#

前端 未结 2 1752
鱼传尺愫
鱼传尺愫 2021-02-12 18:26

I\'m working on a console application on C# and I need to open the console maximized. When I just hit the maximize button on the console window, it maximizes only on height and

相关标签:
2条回答
  • 2021-02-12 18:41

    Can't with the CLR. Need to import Win32 API calls and poke your container window. The following might help.

    using System.Diagnostics;
    using System.Runtime.InteropServices;
    
    [DllImport("user32.dll")]
    public static extern bool ShowWindow(System.IntPtr hWnd, int cmdShow);
    
    private static void Maximize()
    {
        Process p = Process.GetCurrentProcess();
        ShowWindow(p.MainWindowHandle, 3); //SW_MAXIMIZE = 3
    }
    
    0 讨论(0)
  • 2021-02-12 18:53
        [DllImport("kernel32.dll", ExactSpelling = true)]
    
        private static extern IntPtr GetConsoleWindow();
        private static IntPtr ThisConsole = GetConsoleWindow();
    
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    
        private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
        private const int HIDE = 0;
        private const int MAXIMIZE = 3;
        private const int MINIMIZE = 6;
        private const int RESTORE = 9;
    
    
        static void Main(string[] args)
        {
           ShowWindow(ThisConsole, MINIMIZE);
        }
    
    0 讨论(0)
提交回复
热议问题