虽然增加了放大镜的功用,但是在举行像素级的定位时,照样不容易准确定位,在用鼠标操纵时要转变一两个像素的位置照样有些难题的。
处置惩罚键盘按下事宜
/// <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键不要松开,再按上下左右键能够转变截图地区的大小。
以上就是C#开辟实例-订制屏幕截图东西(八)增加键盘操纵截图功用代码示例的细致内容,更多请关注ki4网别的相干文章!