I've been messing around in microsoft visual studio 2013, and I made a console application, but I was wonder if there was a way to make a fixed size for it (height/width), meaning it can't be resized whatsoever? If anyone knows if this is possible, I'd appreciate if you can help me. Thank you!
4 Answers
In order to achieve this effect, you need to use some C++ class library:
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();
}
Hope this is useful.

- 386
- 3
- 20

- 81
- 1
- 1
-
-
@LuizLoyola https://learn.microsoft.com/de-de/windows/desktop/menurc/wm-syscommand – Jiyan Akgül Jul 04 '18 at 10:32
Console.SetWindowSize
will be your friend.

- 2,433
- 5
- 39
- 69

- 1,090
- 10
- 19
-
1That doesn't make it fixed though does it? People are still able to adjust it. – Donavon Aug 18 '15 at 01:44
This is an absolutely horrible solution but you could call throughout your code a "check size" method that checks Console.WindowHeight and Console.WindowWidth and resets them if they are not equal, it won't stop people resizing, but will at least keep it to the size you want.
Edit: The reason I post what I feel is a horrible solution, is because as far as i'm aware there is no builtin functionality to allow what your trying to do, i'm giving you a workaround.
private void CheckAndResetWindowSize(){
if(Console.WindowHeight != 300 || Console.WindowWidth != 500) {
Console.SetWindowSize(500, 300);
}
}

- 515
- 3
- 12
But one thing you will face Windows snap features.
im still finding solution for console
here is solution for Winform app
How can i programmatically use aero snap features from C# code

- 31
- 1
- 6
-
This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31224732) – Nick Vu Mar 10 '22 at 16:28