获取显示器坐标和分辨率/多台显示器

时间:2018-07-24 16:31:21

标签: c# multiple-monitors

我想获取每个屏幕的坐标和分辨率。我目前使用:

foreach (Screen screen in Screen.AllScreens) {

    Rectangle bounds = screen.Bounds;

    float displayScale = screen.Primary ? 1f : 1.25f;

    bounds.Width = (int)(bounds.Width * displayScale);
    bounds.Height = (int)(bounds.Height * displayScale);
    bounds.X = 0;
    bounds.Y = 0;

    Console.WriteLine(screen.Bounds + " => " + bounds);

    g.DrawRectangle(new Pen(new SolidBrush(Color.FromArgb(220, 0, 0, 0)), 5f), bounds);
}

输出:

{X=0,Y=0,Width=1920,Height=1080} => {X=0,Y=0,Width=1920,Height=1080}
{X=-3840,Y=-941,Width=3072,Height=1728} => {X=0,Y=0,Width=3840,Height=2160}

问题是,我不能绘制负坐标。另外,我想自动获取显示器的比例因子。

这是我所期望的: Screenshot with screen order and Coordiantes

0 个答案:

没有答案