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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • python 3.6安装cPickle

    python 3.6安装cPicklepython36找不到pickle这个包,直接使用import_pickleascPickle即可,亲测可用https://blog.csdn.net/bailixuance/article/details/850544591、在python2.X中,需要安装cPickle,2、在python3.X中,这个包已被别的包替换,使用以下语句即可:import_picklea…

    2022年6月16日
    117
  • java 用户态_深入理解内核态和用户态

    java 用户态_深入理解内核态和用户态1.内核态和用户态、内核线程和用户线程等解释操作系统调度CPU的最小单元是线程,也叫轻量级进程(LightWeightProcess),在一个进程里可以创建多个线程,这些线程都拥有各自的计数器、堆栈和局部变量等属性,并且能够访问共享的内存变量。处理器在这些线程上高速切换,让使用者感觉到这些线程在同时执行。系统的用户空间和内核空间:虚拟内存被操作系统划分成两块:内核空间和用户空间,内核空间是内…

    2022年9月17日
    2
  • log4j2 debug_log4j原理

    log4j2 debug_log4j原理长话短说吧。相信大家已经被Log4j2的重大漏洞刷屏了,估计有不少小伙伴此前为了修bug已经累趴下了。很不幸,我的小老弟小二的SpringBoot项目中恰好用的就是Log4j2,版本特喵的还是2.14.1,在这次漏洞波及的版本范围之内。第一时间从网上得知这个漏洞的消息后,小二吓尿了。赶紧跑过来问老王怎么解决。老王先是给小二提供了一些临时性的建议,比如说:JVM参数添加-Dlog4j2.formatMsgNoLookups=truelog4j2.formatMsgNoLooku

    2025年7月2日
    4
  • 怎么从安卓设备转移数据到苹果_换手机了数据怎么办?这样做安卓、苹果手机数据一键转移…

    怎么从安卓设备转移数据到苹果_换手机了数据怎么办?这样做安卓、苹果手机数据一键转移…(2)借助iCloud云备份①确保手机已经连接WiFi,然后在手机“设置”中,依次点击“AppleID——iCloud——iCloud云备份”,开启iCloud云备份功能,然后点击“立即备份”。②接下来就是要将iCloud云备份上的数据下载到新手机上了。如何已经设置了新手机,那需要先抹掉它。依次点击“设置——通用——还原——抹掉所有内容和设置”即可。③手机开机后,往下进行操作,直到看到“应用与数…

    2022年5月26日
    52
  • unity 三维地球_three.js地球

    unity 三维地球_three.js地球本数字地球全部由作者自由开发完成,未使用任何第三方插件,拥有完全知识产权。2021年10月9日更新已支持离线版高程数据和离线卫星影像数据。2021年1月22日更新全球任意位置模型可正常加载,无变形抖动。2021年12月15日更新日出、日落、大气散射、蓝天效果。说明这个不是GIS软件,是一个带地形的三维地球。2021年11月24日更新支持。2021年11月15日更新支持。,运行流畅无卡顿,占用内存小,最大等级可达到地图20级。在线加载全球地形,也可。…

    2022年9月19日
    1
  • c++ 二维vector_vector如何重置

    c++ 二维vector_vector如何重置初始化二维vector,为r*c的vector,所有值为0.1.直接用初始化方法(刚开始没想到)vector>newOne(r,vector(c,0));2.用resize()来控制大小vector>res;res.resize(r);//r行for(intk=0;k

    2022年9月18日
    0

发表回复

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

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