C#软件开发实例.个人定制自己的屏幕抓图工具(八)加入了截图功能键盘

C#软件开发实例.个人定制自己的屏幕抓图工具(八)加入了截图功能键盘

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

章文件夹

尽管加入了放大镜的功能,可是在进行像素级的定位时,还是不easy精确定位,在用鼠标操作时要改变一两个像素的位置还是有些困难的。

处理键盘按下事件

        /// <summary>
        /// 处理键盘按下事件
        /// 用于实现下面功能:
        /// 当用户按下Esc键时,退出截图过程;
        /// Shift + Enter 開始截图的功能;
        /// 使用键盘的上下左右键调整截图位置的功能。
        /// Shift + 上下左右键调整截图区域大小的功能;
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                ExitCutImage(true);
                // 假设不加这一句。热键仅仅能在窗体隐藏后使用一次,之后就不起作用了。
                //RegisterHotKey(Handle, 100, 2 | 1, Keys.A);
            }
            if (e.Shift && e.KeyCode == Keys.Enter)
            {
                if (!this.lbl_CutImage.Visible)
                {
                    this.isCuting = true;
                    this.beginPoint = MousePosition;
                    this.endPoint = MousePosition;
                    SaveCutImageSize(MousePosition, MousePosition);
                    UpdateCutInfoLabel(UpdateUIMode.ShowInfoBox | UpdateUIMode.ShowCutImage);
                }
            }
            if (e.KeyCode == Keys.Left)
            {
                if (this.lbl_CutImage.Visible)
                {
                    if (e.Shift)
                    {
                        if (this.cutImageRect.Width > 1)
                        {
                            this.cutImageRect.Width -= 1;
                            Cursor.Position = new Point(Cursor.Position.X - 1, Cursor.Position.Y);
                            UpdateCutInfoLabel(UpdateUIMode.None);
                        }
                    }
                    else
                    {
                        if (this.cutImageRect.Left > -1)
                        {
                            this.cutImageRect.X -= 1;
                            UpdateCutInfoLabel(UpdateUIMode.None);
                        }
                    }
                }
                else
                {
                    if (Cursor.Position.X > -1)
                    {
                        Cursor.Position = new Point(Cursor.Position.X - 1, Cursor.Position.Y);
                    }
                }
            }
            if (e.KeyCode == Keys.Right)
            {
                if (this.lbl_CutImage.Visible)
                {
                    if (e.Shift)
                    {
                        if (this.cutImageRect.Right < this.Width + 1)
                        {
                            this.cutImageRect.Width += 1;
                            Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y);
                            UpdateCutInfoLabel(UpdateUIMode.None);
                        }
                    }
                    else
                    {
                        if (this.cutImageRect.Right < this.Width + 1)
                        {
                            this.cutImageRect.X += 1;
                            UpdateCutInfoLabel(UpdateUIMode.None);
                        }
                    }
                }
                else
                {
                    if (Cursor.Position.X < this.Width + 1)
                    {
                        Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y);
                    }
                }
            }

            if (e.KeyCode == Keys.Up)
            {
                if (this.lbl_CutImage.Visible)
                {
                    if (e.Shift)
                    {
                        if (this.cutImageRect.Height > 1)
                        {
                            this.cutImageRect.Height -= 1;
                            Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y - 1);
                            UpdateCutInfoLabel(UpdateUIMode.None);
                        }
                    }
                    else
                    {
                        if (this.cutImageRect.Top > -1)
                        {
                            this.cutImageRect.Y -= 1;
                            UpdateCutInfoLabel(UpdateUIMode.None);
                        }
                    }
                }
                else
                {
                    if (Cursor.Position.Y > -1)
                    {
                        Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y - 1);
                    }
                }
            }
            if (e.KeyCode == Keys.Down)
            {
                if (this.lbl_CutImage.Visible)
                {
                    if (e.Shift)
                    {
                        if (this.cutImageRect.Bottom < this.Height + 1)
                        {
                            this.cutImageRect.Height += 1;
                            Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y + 1);
                            UpdateCutInfoLabel(UpdateUIMode.None);
                        }
                    }
                    else
                    {
                        if (this.cutImageRect.Bottom < this.Height + 1)
                        {
                            this.cutImageRect.Y += 1;
                            UpdateCutInfoLabel(UpdateUIMode.None);
                        }
                    }
                }
                else
                {
                    if (Cursor.Position.Y < this.Height + 1)
                    {
                        Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y + 1);
                    }
                }
            }
        }

处理键盘抬起事件

        /// <summary>
        /// 处理键盘抬起事件
        /// Shift + Enter 開始截图。当松开Shitf键后。
        /// 停止截图区域大小的设置。不然的话鼠标移动还会改变截取区域的大小;
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.ShiftKey)
            {
                if (this.isCuting)
                {
                    this.isCuting = false;
                    this.pictureBox_zoom.Hide();

                    this.lastMouseMoveTime = 0;
                    UpdateCutInfoLabel(UpdateUIMode.None);
                }
            }
        }

用键盘操作截图的功能说明:

按下截图快捷键(一般是:Ctrl + Shift + A)后,能够移动鼠标到大概的位置。然后就能够通过键盘的上下左右键精确移动鼠标的位置,在精确定位截图的位置后,就能够按下Shift 键再按 Enter键。Shift键不要松开,这时能够按上下左右键改变截图区域的大小。松开Shift键完毕截图区域大小设置。

这时你能够通过上下左右键以改变截图区域的位置,按Shift不要松开按键,按箭头键来改变拍摄区域的大小。

版权声明:本文博客原创文章,博客,未经同意,不得转载。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/117479.html原文链接:https://javaforall.net

(0)
上一篇 2022年1月5日 上午7:00
下一篇 2022年1月5日 上午7:00


相关推荐

  • 云邦互联免费空间(免备案,无广告)「建议收藏」

    云邦互联免费空间(免备案,无广告)「建议收藏」【1G免费全能空间,免备案,无广告】1G全能空间+100M数据库(Mysql5.5)支持的脚本:ASP、PHP(5.2-7.0)、.NET(2.0/4.0)没有任何限制,详细功能请访问:https://www.yunzz.net/host/free.html(云邦互联)推广员:ftp257684p…

    2022年6月18日
    27
  • 学习分享——location.hash的用法「建议收藏」

    学习分享——location.hash的用法「建议收藏」【学习分享】location.hash的用法location对象:设置或获取当前URL的信息使用location对象可以设置或返回URL中的一些信息,一个完整的URL地址的格式为:协议://主机:端口

    2022年7月4日
    30
  • bzero和memset的区别

    bzero和memset的区别1 void memset void s intc size tn nbsp nbsp nbsp nbsp nbsp nbsp nbsp 总的作用 将已开辟内存空间 s 的首 n 个字节的值设为值 c nbsp nbsp nbsp nbsp nbsp nbsp nbsp 2 memset 函数常用于内存空间初始化 如 nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp charstr 100 nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp memset str 0 100 nbsp nbsp nbsp nbsp nbsp nbsp nbsp 3 memset 可以方便

    2026年3月16日
    2
  • Linux flow offload提高路由转发效率

    Linux flow offload提高路由转发效率凡是正确的东西 该来的最终还是会来的 当然了 经理可能也有同感 来看看几年前我写的文章 利用 nf conntrack 机制存储路由 省去每包路由查找 https blog csdn net dog250 article details 在 Linux 的连接跟踪 nf conntrack 中缓存私有数据省去每次查找 https blog csdn net dog

    2026年3月18日
    3
  • latex 中括号_文件标题中用小括号用法

    latex 中括号_文件标题中用小括号用法Z单边大括号align或alignedarraycase\left\\{和\right.控制括号大小使用\left和\right使用\big,\Big,\bigg,\Bigg控制括号的大小各种括号单边大括号align或aligned$$f(x)=\left\{\begin{aligned}x&=\cos(t)\\y&=\sin(t)\\…

    2022年8月31日
    6
  • 科大讯飞,让AI更通人性

    科大讯飞,让AI更通人性

    2026年3月14日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号