C # Development Example-Custom screenshot tool (eight) Add keyboard action screenshot function code example

Source: Internet
Author: User

Although the function of magnifying glass, but in the pixel-level positioning, still not easy to pinpoint precise, in the mouse operation to change the position of one or two pixels is still a bit difficult.

Handling Keyboard Press Events

        <summary>////Handling Keyboard Press Events////For the following functions:///////When the user presses the ESC key, exit the process;///Shift + Enter start function;//////Use the keyboard to adjust the position of the next or next key function;///Shift + up or down to adjust the size of the area;//</summary>//<param N Ame= "Sender" ></param>//<param name= "E" ></param> private void Form1_keydown (object se                NDEr, KeyEventArgs e) {if (E.keycode = = Keys.escape) {Exitcutimage (true);                If you do not add this, the hotkey can only be used once after the window is hidden, and then it will not work.            RegisterHotKey (Handle, 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.c Utimagerect.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 &lt ; 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.Vis ible) {if (E.shift) {if (this.cutimagerect.h                            Eight > 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 (t his.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 &Lt 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); }                }            }        }

Handling Keyboard Lift Events

        <summary>////        handle keyboard Lift Events///        Shift + Enter to start, when the SHITF key is released,///To        Stop the setting of the area size, otherwise the mouse movement will also change the size of the interception area;        </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);}}}        

The function of the keyboard operation description:

Press the shortcut key (usually: Ctrl + Shift + A), you can move the mouse to the approximate position, and then you can move the mouse position by the keyboard, the next key to the precise location, in the position of the precise positioning, you can press the SHIFT key and then press ENTER key, the SHIFT key do not release, At this point, you can press the next key to change the size of the area, release the SHIFT key to complete the area size setting;

At this point you can change the position of the area by the next key, press the SHIFT key do not release, and then press the left and right key can change the size of the area.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.