我正在C#上的控制台应用程序工作,我需要打开最大化的控制台。当我刚刚点击控制台窗口上的最大化按钮时,它只能在高度上而不是在宽度上最大化。我试图使用下面的代码:最大化控制台窗口 - C#
Console.WindowWidth = 150;
Console.WindowHeight = 61;
这几乎在我的计算机上工作,但在其他计算机上出现错误。 我应该怎么做才能最大化控制台?
我正在C#上的控制台应用程序工作,我需要打开最大化的控制台。当我刚刚点击控制台窗口上的最大化按钮时,它只能在高度上而不是在宽度上最大化。我试图使用下面的代码:最大化控制台窗口 - C#
Console.WindowWidth = 150;
Console.WindowHeight = 61;
这几乎在我的计算机上工作,但在其他计算机上出现错误。 我应该怎么做才能最大化控制台?
不能用CLR。需要导入Win32 API调用并戳动你的容器窗口。以下可能会有所帮助。
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
}
[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);
}
_What错误你的get_?你读过它吗? – SLaks
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683193(v=vs.85).aspx – SLaks
阅读此内容并查看SLaks评论:http://stackoverflow.com/questions/ 7670633/c-sharp-columns-for-a-console-in-c-sharp –