c# - 使用跨越所有显示器的 C# 绘制线
问题描述
我有一个多显示器设置,我想在用户移动光标时绘制一条垂直和水平线。我要绘制的线条应该跨越所有显示器。我不完全确定如何调整我的表单以使其成为可能,因为当我将其设为全屏时,它只会最大化到一台显示器。
我是否必须为每个监视器制作一个表格并在光标移动时向每个监视器发送信号以重新绘制线条?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace fitAllScreens
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
FullScreen();
}
public void FullScreen()
{
List<int> xBounds = new List<int>() {};
List<int> yBounds = new List<int>() {};
foreach (Screen screen in Screen.AllScreens)
{
var bounds = screen.Bounds;
xBounds.Add(bounds.X);
xBounds.Add(bounds.Right);
yBounds.Add(bounds.Y);
yBounds.Add(bounds.Bottom);
}
int minX = xBounds.Min();
int maxX = xBounds.Max();
int minY = yBounds.Min();
int maxY = yBounds.Max();
Console.WriteLine(minX + " - " + maxX + " - " + minY + " - " + maxY);
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
var graphics = e.Graphics;
base.OnPaint(e);
// Draw ruler guides
Console.WriteLine(Cursor.Position);
var pos = this.PointToClient(Cursor.Position);
using (var pen = new Pen(Color.Red))
{
pen.DashStyle = DashStyle.Dot;
var screenBounds = Screen.PrimaryScreen.Bounds;
graphics.DrawLine(pen, pos.X, screenBounds.Y, pos.X, screenBounds.Height);
graphics.DrawLine(pen, screenBounds.X, pos.Y, screenBounds.Width, pos.Y);
}
}
}
}
解决方案
推荐阅读
- r - Group_by 用于 R 中的连续模式
- python - 声明的含义
- git - Buildbot:如何获取自上次成功构建以来更改的文件列表?
- ios - 如何使用 Swift 更改或更新数组字符串
- python - 防止生成器产生相同的对象两次
- c++ - 将 C++ 数组解包为函数调用的参数
- reactjs - sending data from client to socket server using socket.io-client library
- mean-stack - 从角度服务器(安装了letsencrypt证书)到节点服务器(安装了自签名证书)通信时出现ERR_CERT_AUTHORITY_INVALID错误
- terraform - 为什么版本控制声明后没有等号“=”
- android - 在Android中修改单元测试时如何跳过构建Apk