Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the screen size of Console Application?

How do you get the screen size in a console application?

like image 724
user1344948 Avatar asked May 20 '12 17:05

user1344948


2 Answers

var w = Console.WindowWidth;
var h = Console.WindowHeight;

--EDIT--

Screen.PrimaryScreen.Bounds 
Screen.PrimaryScreen.WorkingArea
like image 153
L.B Avatar answered Oct 17 '22 07:10

L.B


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"));
            }               
        }
like image 23
Iliya Tryapitsin Avatar answered Oct 17 '22 07:10

Iliya Tryapitsin