gpt4 book ai didi

c# - 桌面截屏目标区域

转载 作者:行者123 更新时间:2023-12-04 00:41:35 27 4
gpt4 key购买 nike

我正在尝试在 C# 中重新创建一个 Winform 应用程序,该应用程序与窗口提供的截图工具具有相同的功能。也就是说,允许用户在桌面上拖动一个矩形并将里面的内容捕获为图像。

目前我只能用鼠标绘制一个矩形,这在winform中。谁能指出我如何做到这一点,以便我可以在整个桌面上做到这一点?

我绘制矩形的代码如下:

 Rectangle rect; 
public Form1()
{
InitializeComponent();

// set the cursor to be a + sign
this.Cursor = System.Windows.Forms.Cursors.Cross;
this.DoubleBuffered = true;
}

private void Form1_MouseDown(object sender, MouseEventArgs e)
{
// e.X and e.Y are used to get the X and Y pos of the mouse
rect = new Rectangle(e.X, e.Y, 0, 0);
this.Invalidate();
}

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// draw rectangle as mouse moves
rect = new Rectangle(rect.Left,rect.Top, e.X - rect.Left, e.Y - rect.Top);
}
this.Invalidate();
}

private void Form1_Paint(object sender, PaintEventArgs e)
{
// Replace "Color.Red" with any color and repalce "2" with any size you like.
using (Pen pen = new Pen(Color.Red, 2))
{
e.Graphics.DrawRectangle(pen, rect);
}
}
}

我一直在网上四处寻找,但我的搜索还没有提供任何有用的信息。

任何帮助将不胜感激。

最佳答案

关于c# - 桌面截屏目标区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18316693/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com