額……
首先是有一個需求,兩個顯示器,程序自動獲取自己所在的顯示器大小,並顯示到右下角。
我們都知道C#有一個Screen.PrimaryScreen.Bounds,可以獲取屏幕的完整尺寸,但是隻能獲取主顯示器的尺寸,後來我發現又一個Screen.GetBounds(this),可以獲取程序所在的屏幕尺寸。
代碼如下
Console.WriteLine("主顯示器完整尺寸:");
Console.WriteLine("寬:" + Screen.PrimaryScreen.Bounds.Width);
Console.WriteLine("高:" + Screen.PrimaryScreen.Bounds.Height);
Console.WriteLine("主顯示器工作尺寸(排除任務欄、工具欄):");
Console.WriteLine("寬:" + Screen.PrimaryScreen.WorkingArea.Width);
Console.WriteLine("高:" + Screen.PrimaryScreen.WorkingArea.Height);
Console.WriteLine("當前顯示器完整尺寸:");
Console.WriteLine("寬:" + Screen.GetBounds(this).Width);
Console.WriteLine("高:" + Screen.GetBounds(this).Height);
Console.WriteLine("當前顯示器工作尺寸(排除任務欄、工具欄):");
Console.WriteLine("寬:" + Screen.GetWorkingArea(this).Width);
Console.WriteLine("高:" + Screen.GetWorkingArea(this).Height);
來回就這麼兩句,還有其他的功能可以看一下官方幫助文檔。