Chapter folder (i) function overview (ii) Create a project, register a hotkey, Show main form (c) Tray icon and menu implementation (iv) BASIC function realization (v) optimization for flicker lag during drag-and-drop (vi) Add Configuration management function (vii) Add Magnifier function (eight) Add keyboard functions (ix) using your own definition of the cursor, QQ when the cursor (10) includes the mouse pointer shape
Although the function of magnifying glass, but in the pixel-level positioning, or not easy precise positioning, when using the mouse 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 key around the function. Shift + up or down key to adjust the size of the function;//</summary>//<param name= "sender" ></param>//&L T;param name= "E" ></param> private void Form1_keydown (object sender, KeyEventArgs e) {if (E.keycode = = Keys.escape) {Exitcutimage (true); Suppose not to add this sentence. Hotkeys can only be used once after the form 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.lb l_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.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< 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. /// Stop the setting of the area size. Otherwise, the mouse movement will 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:
When you press the shortcut key (usually: Ctrl + Shift + A), you can move the mouse to the approximate position. Then you can move the mouse position precisely through the keyboard's left and right keys, and after the position is precisely positioned, you can press the SHIFT key and press the ENTER key. Shift key do not release, at this time can press the next key around 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 left and right keys, press SHIFT to not release the button, press the arrow keys to change the size of the shooting area.
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
C # Software Development example. Customize your own screen Capture tool (eight) added functional keyboard