How can I set a minimum console size in console application C# that users can not change? Thank you in advance for answers ;)
Asked
Active
Viewed 1,045 times
2
-
You can't. A console application doesn't have any control over its host. – Phylogenesis Mar 06 '18 at 12:10
-
what have you tried, consider https://stackoverflow.com/q/15099523/1132334 – Cee McSharpface Mar 06 '18 at 12:12
-
you can set the [console size](https://msdn.microsoft.com/en-us/library/system.console.setwindowsize(v=vs.110).aspx), but you cannot set the minimum size – styx Mar 06 '18 at 12:12
-
The user is in control over his console, your program is merely the humble visitor. Give them a good reason to not to want to make it smaller. – Hans Passant Mar 06 '18 at 12:33
1 Answers
2
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();
}

Roman Marusyk
- 23,328
- 24
- 73
- 116
-
-
of course, infinity loop. But as a workaround why not :) And the asnwer is: There aren't any resize Event for Console – Roman Marusyk Mar 06 '18 at 12:16
-
2well we [could do lots of stuff](https://stackoverflow.com/a/2880337/1132334) with [this handle](https://stackoverflow.com/a/1277609/1132334). but we should not. – Cee McSharpface Mar 06 '18 at 12:21
-
Also doesn't your solution set the max height of the console, it should resize when the console height or width falls below the given min and max values not when it exceeds them. – trunks1ace Mar 06 '18 at 12:40