C# - 多个桌面壁纸应用程序 - 逻辑问题

发布于 2024-10-11 04:30:05 字数 2295 浏览 5 评论 0原文

我目前正在为这个问题而烦恼。

我要做的事情:

我可以

  • 为每个屏幕生成一个图像
  • 为彼此相邻的两个屏幕创建一个大型图像。
  • 将其设置为平铺壁纸。

我想做的:

  • 支持任意数量的显示器
  • 支持显示器的所有偏移,例如显示器上方、下方或对角线。

我已阅读这篇 MSDN 文章,发现它非常有帮助:

http ://blogs.msdn.com/b/oldnewthing/archive/2007/09/24/5083738.aspx

但我仍然坚持我需要使用的逻辑:

  • 计算我需要什么尺寸的图像监视器的变化
  • 创建应用监视器偏移的壁纸

我的程序布局如下:

ScreenInfo 类:

public Bitmap ChosenWallPaper { get; private set; }
public Rectangle ScreenArea { get; private set; }

int ScreenNumber { get; set; }

public string ScreenDescription { get { return "Screen: " + ScreenNumber + " " + ScreenArea.ToString(); } }

public ScreenInfo(int screenNumber)
{
    this.ScreenNumber = screenNumber;
    ScreenArea = new Rectangle(Screen.AllScreens[screenNumber].Bounds.X, Screen.AllScreens[screenNumber].Bounds.Y, Screen.AllScreens[screenNumber].Bounds.Width, Screen.AllScreens[screenNumber].Bounds.Height);
}

ScreenCollection 类

public List<ScreenInfo> ScreenList { get; private set; }

public ScreenCollection()
{
    ScreenList = new List<ScreenInfo>();

    for (int i = 0; i < Screen.AllScreens.Count(); i++)
    {
        ScreenList.Add(new ScreenInfo(i));
    }
}

public Rectangle CalculateMainBitmapSize()
{

}

我的源代码的其余部分尚未实现。

谢谢!

编辑:

我已经弄清楚如何用一些非常hacky、可怕的代码来相互表示两个监视器,但我开始了解监视器是如何布局的......

private void SizeScreens()
{
    pictureBox1.Height = Desktops.ScreenList[0].ScreenArea.Height / 10;
    pictureBox1.Width = Desktops.ScreenList[0].ScreenArea.Width / 10;

    pictureBox2.Height = Desktops.ScreenList[1].ScreenArea.Height / 10;
    pictureBox2.Width = Desktops.ScreenList[1].ScreenArea.Width / 10;
}

private void PositionScreens()
{
    Point Screen1Location = new Point(Desktops.ScreenList[0].ScreenArea.X,Desktops.ScreenList[0].ScreenArea.Y);
    Point Screen2Location = new Point(Origin.X + (Desktops.ScreenList[1].ScreenArea.X / 10),Origin.Y + (Desktops.ScreenList[1].ScreenArea.Y / 10));

    pictureBox1.Location = Origin;
    pictureBox2.Location = Screen2Location;
}

I'm currently tearing my hair out with this problem.

Where I'm up to:

I can

  • Generate an image for each screen
  • Create a mega-image for two screens next to each other.
  • Setting this as a tiled wallpaper.

What I want to do:

  • Support any number of monitors
  • Support all offsets of monitors, such as monitors above, or below, or diagonal.

I have read this MSDN article and found it very helpful:

http://blogs.msdn.com/b/oldnewthing/archive/2007/09/24/5083738.aspx

But I am still stuck on the logic I need to use to:

  • Calculate what size image I need for any variation of monitors
  • Create the wallpaper applying the offset of monitors

My program is laid out as follows:

ScreenInfo Class:

public Bitmap ChosenWallPaper { get; private set; }
public Rectangle ScreenArea { get; private set; }

int ScreenNumber { get; set; }

public string ScreenDescription { get { return "Screen: " + ScreenNumber + " " + ScreenArea.ToString(); } }

public ScreenInfo(int screenNumber)
{
    this.ScreenNumber = screenNumber;
    ScreenArea = new Rectangle(Screen.AllScreens[screenNumber].Bounds.X, Screen.AllScreens[screenNumber].Bounds.Y, Screen.AllScreens[screenNumber].Bounds.Width, Screen.AllScreens[screenNumber].Bounds.Height);
}

ScreenCollection Class

public List<ScreenInfo> ScreenList { get; private set; }

public ScreenCollection()
{
    ScreenList = new List<ScreenInfo>();

    for (int i = 0; i < Screen.AllScreens.Count(); i++)
    {
        ScreenList.Add(new ScreenInfo(i));
    }
}

public Rectangle CalculateMainBitmapSize()
{

}

The rest of my source code hasn't been implemented yet.

Thanks!

EDIT:

I've figured out how to represent two monitors with each other with some REALLY hacky, horrible code, but I'm starting to understand how the monitors are laid out a bit more...

private void SizeScreens()
{
    pictureBox1.Height = Desktops.ScreenList[0].ScreenArea.Height / 10;
    pictureBox1.Width = Desktops.ScreenList[0].ScreenArea.Width / 10;

    pictureBox2.Height = Desktops.ScreenList[1].ScreenArea.Height / 10;
    pictureBox2.Width = Desktops.ScreenList[1].ScreenArea.Width / 10;
}

private void PositionScreens()
{
    Point Screen1Location = new Point(Desktops.ScreenList[0].ScreenArea.X,Desktops.ScreenList[0].ScreenArea.Y);
    Point Screen2Location = new Point(Origin.X + (Desktops.ScreenList[1].ScreenArea.X / 10),Origin.Y + (Desktops.ScreenList[1].ScreenArea.Y / 10));

    pictureBox1.Location = Origin;
    pictureBox2.Location = Screen2Location;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

隔岸观火 2024-10-18 04:30:05

您可以使用 GetSystemMetrics< 查询虚拟屏幕的大小/a> 函数,参数为 SM_CXVIRTUALSCREENSM_CYVIRTUALSCREEN。这应该会给你图像的大小。

监视器的位置可以通过“EnumDisplayMonitors”获得,但这有点复杂,因为它需要回调函数。

// 编辑:不知道 Screen.AllScreens,但我猜你在那里得到了屏幕的位置。
您应该将壁纸放在这些位置,将屏幕以负坐标包裹在右侧。虚拟屏幕的原点位于主显示器的左上角。

You can query the size of the virtual screen using the GetSystemMetrics function with the parameters SM_CXVIRTUALSCREEN and SM_CYVIRTUALSCREEN. That should give you the size of your image.

The positions of the monitors can be obtained through ´EnumDisplayMonitors`, but this is a bit more complicated as it requires a callback function.

// edit: Wasn't aware of Screen.AllScreens, but I guess you get the positions of the screens there.
You should just put you wallpapers at these positions, wrapping screens with negative coordinates to the right. The origin of the virtual screen is in the top left corner of the main monitor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文