c# - 有没有办法制作固定(高度/宽度)控制台?

Don*_*von 2 c# console height fixed width

我一直在 microsoft visual studio 2013 中乱搞,我制作了一个控制台应用程序,但我想知道是否有办法为其设置固定大小(高度/宽度),这意味着它无法调整大小?如果有人知道这是否可行,如果您能帮助我,我将不胜感激。谢谢!

小智 5

为了达到这个效果,需要用到一些C++类库吗?

const int MF_BYCOMMAND = 0x00000000;
const int SC_MINIMIZE = 0xF020;
const int SC_MAXIMIZE = 0xF030;
const int SC_SIZE = 0xF000;

[DllImport("user32.dll")]
public static extern int DeleteMenu(IntPtr hMenu, int nPosition, int wFlags);

[DllImport("user32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

[DllImport("kernel32.dll", ExactSpelling = true)]
private static extern IntPtr GetConsoleWindow();

static void Main(string[] args)
{
    Console.WindowHeight = 25;
    Console.WindowWidth = 80;

    DeleteMenu(GetSystemMenu(GetConsoleWindow(), false), SC_MINIMIZE, MF_BYCOMMAND);
    DeleteMenu(GetSystemMenu(GetConsoleWindow(), false), SC_MAXIMIZE, MF_BYCOMMAND);
    DeleteMenu(GetSystemMenu(GetConsoleWindow(), false), SC_SIZE, MF_BYCOMMAND);

    Console.WriteLine("Yes, its fixed!");
    Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)

希望这是有用的。