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


相关推荐

  • java8 groupingby_Java8stream中利用groupingBy进行多字段分组求和

    java8 groupingby_Java8stream中利用groupingBy进行多字段分组求和对集合按照单个属性分组、分组计数、排序Listitems=Arrays.asList(“apple”,”apple”,”banana”,”apple”,”orange”,”banana”,”papaya”);//分组Map>result1=items.stream().collect(Collectors.groupingBy(Function.identity()));…

    2022年8月20日
    16
  • 微信公众号推广_微信公众号名字

    微信公众号推广_微信公众号名字微信5.0发布2013年8月5日,伴随着微信5.0iPhone版的发布,公众平台也进行了重要的更新,主要包括:1)运营主体为组织,可选择成为服务号或者订阅号;2)服务号可以申请自定义菜单;3)使用QQ登录的公众号,可以升级为邮箱登录;4)使用邮箱登录的公众号,可以修改登录邮箱;5)编辑图文消息可选填作者;6)群发消息可以同步到腾讯微博。其中,大家议论最多的当属前两

    2022年9月1日
    5
  • c语言表白用代码(1)

    c语言表白用代码(1)不多说,直接上代码,有用拿走,侵权立删。希望大家尽早找到自己的另一半。#include&lt;stdio.h&gt;#include&lt;math.h&gt;#include&lt;stdlib.h&gt;#defineI20#defineR340#include&lt;string.h&gt;intmain(){charanswer[4];…

    2022年7月25日
    38
  • leetcode 两数相加(两个数相加分别叫什么)

    publicclasstest{ publicstaticvoidmain(String[]args){ System.out.println("HelloWorld!"); ListNodea=newListNode(0); ListNodeb=newListNode(0); a.val=2; a.next=newListNode(4); a….

    2022年4月10日
    40
  • ant 安装

    ant 安装

    2021年11月28日
    37
  • 直播界的新玩法:你又套路用户!只要钱到位,榜单全干碎

    直播界的新玩法:你又套路用户!只要钱到位,榜单全干碎今天早上好心市民王先生(公众号:hxsmwxs)在翻看AppStore榜单的时候,发现今天凌晨(25号0:00分)榜单更新后有三款应用刷榜,乍一看是两款游戏,一款应用,但好心市民王先生(公众号:hxsmwxs)在下载之后发现了其中一款的秘密,就是下面这款【战舰世界】看看它的排名变化,真是舍得花钱啊下面我们一步步的分析这款应用所有用户点开从名称到截图乍一看就是一款游戏,但从描述中不难发现,他就是一…

    2022年6月5日
    60

发表回复

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

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