屏幕捕获桌面的目标区域

本文关键字:目标 区域 桌面 屏幕 | 更新日期: 2023-09-27 18:28:08

我正试图在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);
        }
    }
}

我一直在网上寻找,但我的搜索还没有提供任何有用的东西。

如有任何帮助,我们将不胜感激。

屏幕捕获桌面的目标区域

参见:

http://www.codeproject.com/Articles/485883/Create-your-own-Snipping-Tool

和:

http://www.codeproject.com/Articles/21913/TeboScreen-Basic-C-Screen-Capture-Application

作为代码段工具创建的参考。

希望这能有所帮助。