首先是有一个需求,两个显示器,程序自动获取自己所在的显示器大小,并显示到右下角。
我们都知道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);
使用这些方法前引用:System.Windows.Forms。
原文:https://blog.youkuaiyun.com/arrowzz/article/details/60608586
本文介绍如何使用C#在双显示器环境下,自动获取程序所在显示器的尺寸信息,包括完整尺寸和工作尺寸(排除任务栏、工具栏)。通过Screen.GetBounds和Screen.GetWorkingArea方法,结合实例代码展示。
2203

被折叠的 条评论
为什么被折叠?



