简体   繁体   中英

How can I set a minimum console size C#?

How can I set a minimum console size in console application C# that users can not change? Thank you in advance for answers ;)

There aren't any resize Event for Console. But as a workaround you can try (not recommended!):

public static void Main(string[] args)
{
    const int MinHeight = 10;
    const int MinWidth = 10;
    Task.Factory.StartNew(() =>
    {
        while (true)
        {
            if (Console.WindowHeight > MinHeight || Console.WindowWidth > MinWidth)
            {
                Console.SetWindowSize(MinWidth, MinHeight);
            }
        }
    });
    //  Do some work here
    Console.ReadKey();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM