我试图在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);
}
}
}
我一直在网上四处寻找,但我的搜索还不能提供使用的任何东西。
任何帮助将不胜感激。
另请参阅[Greenshot]的源代码(http://sourceforge.net/projects/greenshot/) – ja72