How do I find out the size of the entire desktop? Not the "working area" and not the "screen resolution", both of which refer to only one screen. I want to find out the total width and height of the virtual desktop of which each monitor is showing only a part.
Logo C merupakan sebuah lambang yang merujuk pada Copyright, yang berarti hak cipta.
C adalah huruf ketiga dalam alfabet Latin. Dalam bahasa Indonesia, huruf ini disebut ce (dibaca [tʃe]).
Meskipun C dibuat untuk memprogram sistem dan jaringan komputer namun bahasa ini juga sering digunakan dalam mengembangkan software aplikasi. C juga banyak dipakai oleh berbagai jenis platform sistem operasi dan arsitektur komputer, bahkan terdapat beberepa compiler yang sangat populer telah tersedia.
Bahasa pemrograman C ini dikembangkan antara tahun 1969 – 1972 oleh Dennis Ritchie. Yang kemudian dipakai untuk menulis ulang sistem operasi UNIX. Selain untuk mengembangkan UNIX, bahasa C juga dirilis sebagai bahasa pemrograman umum.
You have two options:
PresentationFramework.dll
SystemParameters.VirtualScreenWidth SystemParameters.VirtualScreenHeight
System.Windows.Forms.dll
SystemInformation.VirtualScreen.Width SystemInformation.VirtualScreen.Height
Use the first option if you developing a WPF application.
I think it's time to bring this answer up to date with a little LINQ, which makes it easy to get the entire desktop size with a single expression.
Console.WriteLine( Screen.AllScreens.Select(screen=>screen.Bounds) .Aggregate(Rectangle.Union) .Size );
My original answer follows:
I guess what you want is something like this:
int minx, miny, maxx, maxy; minx = miny = int.MaxValue; maxx = maxy = int.MinValue; foreach(Screen screen in Screen.AllScreens){ var bounds = screen.Bounds; minx = Math.Min(minx, bounds.X); miny = Math.Min(miny, bounds.Y); maxx = Math.Max(maxx, bounds.Right); maxy = Math.Max(maxy, bounds.Bottom); } Console.WriteLine("(width, height) = ({0}, {1})", maxx - minx, maxy - miny);
Keep in mind that this doesn't tell the whole story. It is possible for multiple monitors to be staggered, or arranged in a nonrectangular shape. Therefore, it may be that not all of the space between (minx, miny) and (maxx, maxy) is visible.
EDIT:
I just realized that the code could be a bit simpler using Rectangle.Union
:
Rectangle rect = new Rectangle(int.MaxValue, int.MaxValue, int.MinValue, int.MinValue); foreach(Screen screen in Screen.AllScreens) rect = Rectangle.Union(rect, screen.Bounds); Console.WriteLine("(width, height) = ({0}, {1})", rect.Width, rect.Height);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With