相关疑难解决方法(0)

19
推荐指数
1
解决办法
7万
查看次数

在多个显示器上绘制所有窗口

我正在使用以下代码在单个显示器上绘制:

Point cursorLocation;
NativeMethods.GetCursorPos(out cursorLocation);
Screen screen = Screen.FromPoint(cursorLocation);

Point h1 = new Point(screen.Bounds.Left, cursorLocation.Y);
Point h2 = new Point(screen.Bounds.Right, cursorLocation.Y);
Point v1 = new Point(cursorLocation.X, screen.Bounds.Top);
Point v2 = new Point(cursorLocation.X, screen.Bounds.Bottom);

using (Graphics graphics = Graphics.FromHwnd(NativeMethods.GetDesktopWindow())) {
    NativeMethods.SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
    graphics.DrawLine(Pens.Red, h1, h2);
    graphics.DrawLine(Pens.Red, v1, v2);
}
Run Code Online (Sandbox Code Playgroud)

本身,这应该 从理论上得出任何显示器上。但是,它仅利用初级。所以,为了解决这个问题,我得到了所有显示器的 DC 并尝试这样做。

IntPtr hdc = NativeMethods.CreateDC("DISPLAY", IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
Graphics graphics = Graphics.FromHdc(hdc);
graphics.DrawLine(Pens.Red, h1, h2);
graphics.DrawLine(Pens.Red, v1, v2);
graphics.Dispose();
NativeMethods.ReleaseDC(IntPtr.Zero, hdc);
Run Code Online (Sandbox Code Playgroud)

想想看,这甚至根本没有绘制到屏幕上。我为 CreateDC 尝试了各种重载,并搜索了 SO …

c# desktop gdi+

5
推荐指数
1
解决办法
3637
查看次数

标签 统计

.net ×1

c# ×1

c#-4.0 ×1

desktop ×1

gdi+ ×1

winforms ×1