桌面的屏幕捕获目标区域 [英] Screen Capture target area of the desktop

查看:57
本文介绍了桌面的屏幕捕获目标区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用C#重新创建一个Winform应用程序,该应用程序具有与Windows截图工具所提供的功能相同的功能.也就是说,允许用户在桌面上拖动一个矩形并捕获其中的任何内容作为图像.

I'm trying to recreate a Winform application in C# that has the same functionality as the snipping tool windows provides. That is, allowing the user to drag a rectangle over the desktop and capture what ever is inside as an image.

目前,我只能用鼠标绘制一个矩形,该矩形位于winform中.谁能指出我的操作方向,以便我可以在整个台式机上进行操作?

At the moment I only have the ability to draw a rectangle with the mouse, and that's within the winform. Can anyone point me in the direction of how to do it so I can do it within the whole desktop?

我绘制矩形的代码如下:

My code for drawing the rectangle is as follows:

 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);
        }
    }
}

我一直在网上闲逛,但是我的搜索尚未提供任何使用.

I've been looking around online, but my searches haven't provided anything of use yet.

任何帮助将不胜感激.

推荐答案

请参阅:

http://www.codeproject.com/Articles/485883/创建自己的截图工具

并且:

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

作为创建剪裁工具的参考.

as references of Snipping tool creation.

希望这会有所帮助.

这篇关于桌面的屏幕捕获目标区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆