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


相关推荐

  • 最近工作方面发生了一些大事情,所以特地为此摇了一挂,请高手进来断一断。…

    最近工作方面发生了一些大事情,所以特地为此摇了一挂,请高手进来断一断。…

    2021年8月4日
    55
  • 小白都能学会的git的命令操作

    小白都能学会的git的命令操作

    2021年8月3日
    85
  • SQL查询语句练习题27道

    练习环境为:XP+SQL2000数据库练习使用的数据库为:学生管理数据库数据库下载地址为:http://download.csdn.net/download/friendan/4648150说明        这是我在学习数据库课时,老师给的27道SELECT语句练习题,在写这篇文章时,老师并没有给参考答案,写这篇文章的目的完全是为了加深我对SQL语句的理解和方便我以后

    2022年4月8日
    48
  • linux安装nodejs环境_ubuntu安装nodejs

    linux安装nodejs环境_ubuntu安装nodejs之前在安装nodejs踩了不少的坑,我结合了之前在网上其他人发的教程,做了补充优化。1.到官网下载与自己系统匹配的nodejs版本中文网站英文网站不知道系统版本号的可以通过uname-a查询系统位数此处下载最新的nodejs也可以下载历史版本,选择自己想要的创建node目录(可以不创建)mkdirnode进去nodejs目录cd…

    2022年9月13日
    0
  • 华为手机桌面时钟天气_华为手机怎么让屏幕显示天气和时钟

    华为手机桌面时钟天气_华为手机怎么让屏幕显示天气和时钟华为手机锁屏时钟软件是一款安卓手机桌面锁屏时钟工具,拥有多种锁屏时钟样式,软件使用界面精致简洁,锁屏也能够看时间,拥有多种时钟颜色可以选择,还可以添加各种提醒服务,到点即可提醒用户,使用方法简单,拥有多种显示模式,需要的伙伴,西西下载使用吧!华为手机锁屏时钟软件特色:锁屏时钟是一款功能齐全又实用的时钟显示软件,主界面是一个自带时间、日期、天气的LED数字时钟和模拟时钟,全屏显示翻页时钟,酷炫美观…

    2022年9月29日
    1
  • HTML5新控件 – 日期和时间选择输入

    HTML5新控件 – 日期和时间选择输入转载自:https://blog.csdn.net/u014063717/article/details/50914466HTML5定义了几个与日期有关的新控件。支持日期控件的浏览器会提供一个方便的下拉式日历,供用户选择。注意:我测试了Chrome和Opera,火狐提供下拉式日历支持,其它浏览器可能仍是一个普通文本框。1,日期控件-date&lt;inputtype="date"valu…

    2022年5月24日
    261

发表回复

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

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