由于截图时可能需要精确截取某一部分,所以需要放大镜的功能,这样截取的时候才更容易定位截图的位置。
添加PictureBox,name属性设置为“pictureBox_zoom”;
在“Form1_Load”事件处理函数中添加以下代码:
//设置放大镜的大小 this.pictureBox_zoom.Width = this.ZoomBoxWidth; this.pictureBox_zoom.Height = this.ZoomBoxHeight;
登录后复制
在“ExitCutImage”方法中添加代码:
在“Form1_MouseUp”事件处理函数中添加代码:
在“ShowForm”方法的else条件最后添加代码:
if (this.ZoomBoxVisible) { UpdateCutInfoLabel(UpdateUIMode.ShowZoomBox); this.pictureBox_zoom.Show(); }
登录后复制
在“UpdateCutInfoLabel”函数最后添加以下代码:
if (this.pictureBox_zoom.Visible || (updateUIMode & UpdateUIMode.ShowZoomBox) != UpdateUIMode.None) { Point zoomLocation = new Point(MousePosition.X + 15, MousePosition.Y + 22); if (zoomLocation.Y + this.pictureBox_zoom.Height > this.Height) { if (zoomLocation.X + this.pictureBox_zoom.Width > this.Width) { zoomLocation = new Point(MousePosition.X - this.pictureBox_zoom.Width - 10, MousePosition.Y - this.pictureBox_zoom.Height - 10); } else { zoomLocation = new Point(MousePosition.X + 15, MousePosition.Y - this.pictureBox_zoom.Height - 15); } } else { if (zoomLocation.X + this.pictureBox_zoom.Width > this.Width) { zoomLocation = new Point(MousePosition.X - this.pictureBox_zoom.Width - 15, MousePosition.Y); } } this.pictureBox_zoom.Location = zoomLocation; if (!this.pictureBox_zoom.Visible) { this.pictureBox_zoom.Show(); } }
登录后复制
在“Form1_KeyUp”事件处理函数中添加以下代码:
为“pictureBox_zoom”添加“Paint”事件处理程序,代码如下:
////// 放大镜组件重绘事件处理程序 /// 实时显示鼠标指针位置放大后的图像 /// /// /// private void pictureBox_zoom_Paint(object sender, PaintEventArgs e) { Bitmap bmp_lbl = new Bitmap(e.ClipRectangle.Width, e.ClipRectangle.Height); int srcWidth = (int)(this.ZoomBoxWidth / 10); int srcHeight = (int)(this.ZoomBoxHeight / 10); Bitmap bmp = new Bitmap(srcWidth, srcHeight); Rectangle srcRect = new Rectangle(MousePosition.X - 5, MousePosition.Y - 4, srcWidth, srcHeight); if (!isCuting) { srcRect = new Rectangle(MousePosition.X - 6, MousePosition.Y - 5, srcWidth, srcHeight); } Graphics g = Graphics.FromImage(bmp); g.DrawImage(screenImage, 0, 0, srcRect, GraphicsUnit.Pixel); g.Dispose(); //Zoom int x, y; for (int row = 0; row编译,运行,截图看看效果吧!
登录后复制
以上就是C#开发实例-订制屏幕截图工具(七)添加放大镜功能的代码示例的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2549497.html