How do you get the screen size in a console application?
-
Screen meaning console size or display resolution? – SLaks May 20 '12 at 17:49
-
i said screen size in a console application not for a console application... there is a difference. and to the one that gave -1 (if it was someone who thought size for the console (which btw if you read the question correctly) it was not) DONT HATE BACAUSE YOU READ WRONG! and to everyone else im sorry for acting up and i appreciate your answers :) – user1344948 May 20 '12 at 18:17
-
@user1344948, the title of your comment literally states *How to get the screen size **of** Console Application?* Dont hate others when you are (partially) wrong... Nonetheless, this thread gives both the size of the console and the screen - win! – devklick Aug 28 '18 at 21:31
-
This question might be old but I have the same problem now. The solution of L.B requires me to add a reference to `System.Windows.Forms` and the solution of Iliya Tryapitsin is OS dependent. It is kinda poor that there is no easy OS independent way to do this inside a console application. – Robert S. Feb 07 '19 at 15:40
3 Answers
var w = Console.WindowWidth;
var h = Console.WindowHeight;
--EDIT--
Screen.PrimaryScreen.Bounds
Screen.PrimaryScreen.WorkingArea

- 114,136
- 19
- 178
- 224
-
not what i was looking for... looking for display size, could have been clearer on that point – user1344948 May 20 '12 at 18:23
-
The `Screen` class is only available with the `System.Windows.Forms` assembly so this might be possible (by adding the reference manually) but would require this assembly only for that purpose. – Robert S. Feb 07 '19 at 15:37
-
@RobertS. I don't think a downvote is fair, At least, it is an answer for some people. Feel free to post a better, OS independent solution and I will upvote it. – L.B Feb 11 '19 at 19:08
-
@L.B Sorry but he explicitly asked for a Console Application and there is no `Screen` class in such a project by default. It might be a solution, but not one to recommend I think, as you add a big dependency only for such a tiny purpose. – Robert S. Apr 29 '19 at 17:01
If you want get display size you can use WMI(Windows Management Instrumentation)
var scope = new ManagementScope();
scope.Connect();
var query = new ObjectQuery("SELECT * FROM Win32_VideoController");
using (var searcher = new ManagementObjectSearcher(scope, query))
{
var results = searcher.Get();
foreach (var result in results)
{
Console.WriteLine("Horizontal resolution: " + result.GetPropertyValue("CurrentHorizontalResolution"));
Console.WriteLine("Vertical resolution: " + result.GetPropertyValue("CurrentVerticalResolution"));
}
}

- 141
- 1
- 1
- 7
-
I am working with Visual Studio on a Windows 10 Virtual machine, running on a MacOS host. This was the only method that truly returned the resolution of the virtual client. The Screen.PrimaryScreen way was returning the resolution of the host. – lukiller Apr 12 '18 at 23:15
If you are looking to change the size of a console application with the size of the screen we first have to get the largest width and height of the window.
var largestWindowX = Console.LargestWindowWidth;
var largestWindowY = Console.LargestWindowHeight;
For a screen that is 1920x1080 the largest X and Y values are X: 240 and Y: 66. By writing the values out to the screen, we can then change the screen size manually to get the respective X and Y coordinates of that screen size.
Now we take the largest value of the last screen size in this case 1600x1024 which is X: 200 and Y: 62 and check if the screen is bigger then or equal to the display and make the console window this big.
if(largestWindowX >= 200 && largestWindowY >= 62)
{
//The values 200 and 40 can be changed depending on what you are making
Console.SetWindowSize(200, 40);
}
//add more if else statments depending how you wish to scale it as.
else
{
//Otherwise any screen size smaller than the sizes added make it this...
Console.SetWindowSize(/*Your X value*/, /*Your Y value*/);
}
If you are looking for a way to find the Display size from the OS, that I have no clue as I am not an advanced programmer, just know some of this vast language.
Though, you could technically use the values of the variables above. for example:
if(largestWindowX == 240 && largestWindowY == 66)
{
Console.WriteLine("This is a 1920x1080 screen");
}
I am not exactly sure that would be an accurate way of telling the screen size. Otherwise if full screen is necessary Alt+Enter works...

- 47,830
- 31
- 106
- 135

- 31
- 2