我正在尝试用 C# 重新创建一个 Winform 应用程序,该应用程序具有与 Windows 截图工具提供的相同功能。也就是说,允许用户在桌面上拖动一个矩形并捕获其中的内容作为图像。
目前我只能用鼠标绘制一个矩形,而且是在 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);
}
}
}
我一直在网上四处寻找,但我的搜索还没有提供任何有用的东西。
任何帮助将不胜感激。
See:
http://www.codeproject.com/Articles/485883/Create-your-own-Snipping-Tool
And:
http://www.codeproject.com/Articles/21913/TeboScreen-Basic-C-Screen-Capture-Application
作为截图工具创建的参考。
希望这可以帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)