浅析如何用C#.NET做屏幕截图软件以及注册全局快捷键(下)
2010-09-30 22:42:37 来源:WEB开发网picBox_Paint
private void picBox_Paint( object sender, PaintEventArgs e ) {
Graphics g = e.Graphics;
if (isDrawing) {
//g.DrawRectangle( penRect, captureRect);
DrawScableRect( captureRect, g );
}
else if (!isDrawned) {
g.DrawLine( penLine, 0, currentPoint.Y, fullScreen.Width, currentPoint.Y );
g.DrawLine( penLine, currentPoint.X, 0, currentPoint.X, fullScreen.Height );
}
}
首先我们需要在鼠标按下时记录矩形的起点,
if (!isDrawing) {
startPoint = e.Location;
captureRect.Location = startPoint;
isDrawing = true;
return;
}
然后在MouseMove事件里面刷新矩形大小,最后调用this.Refresh(),强制窗体重绘,调用Paint方法。
最最后是在MouseUp事件里面检测画图是否完成。这样就停止调用this.Refresh()了。
至于画图形,就要用到Graphics.DrawRectangle()和Graphics.DrawLine(),可以到MSDN查询它们的使用方法。
更多精彩
赞助商链接