上一篇:C#软件开发实例.私人订制自己的屏幕截图工具(七)添加放大镜的功能
虽然添加了放大镜的功能,但是在进行像素级的定位时,还是不容易精确定位,在用鼠标操作时要改变一两个像素的位置还是有些困难的。
处理键盘按下事件
/// <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#软件开发实例.私人订制自己的屏幕截图工具(四)基本截图功能实现,文章链接:http://blog.csdn.net/testcs_dn/article/details/23346683
此代码对应于博客文章:C#软件开发实例.私人订制自己的屏幕截图工具(六)添加配置管理功能,文章链接:http://blog.csdn.net/testcs_dn/article/details/24466763
C#软件开发实例.私人订制自己的屏幕截图工具中使用的光标文件,参考:http://blog.csdn.net/testcs_dn/article/details/30835107
C#精彩实例教程.pd 很好一本入门教程
《C#开发实例大全(基础卷)》筛选、汇集了C#开发从基础知识到高级应用各个层面约600个实例及源代码,每个实例都按实例说明、关键技术、设计过程、详尽注释、秘笈心法的顺序进行了分析解读。全书分6篇共25章,主要...
C# 装饰模式实例... C# 装饰模式实例... C# 装饰模式实例...
ArcGIS+Engine+C#实例开发教程.pdf
C# Gps定位实例.rar 取手机位置
C#程序150实例.rar C#程序150实例.rar C#程序150实例.rar C#程序150实例.rar
c# 模拟 屏幕键盘c# 模拟 屏幕键盘c# 模拟 屏幕键盘c# 模拟 屏幕键盘c# 模拟 屏幕键盘c# 模拟 屏幕键盘c# 模拟 屏幕键盘c# 模拟 屏幕键盘c# 模拟 屏幕键盘c# 模拟 屏幕键盘c# 模拟 屏幕键盘c# 模拟 屏幕键盘c# 模拟 ...
基于C#的软件开发实例,可供程序人员参考
c#皮肤实例源码.c#皮肤实例源码.c#皮肤实例源码.c#皮肤实例源码.c#皮肤实例源码.
ArcGIS Engine + C# 实例开发教程
c#软件开发实例 三个基础c#软件开发实例,入门学习参考实例
C#通讯录实例C#通讯录实例C#通讯录实例
C# 网络通信开发训练-32个实例 C# 网络通信开发训练 实例01 更改计算机名称...... 670 实例02 通过计算机名获取IP地址...... 672 实例03 通过IP地址获取主机名称...... 673 实例04 修改本机IP地址...... 674...
ArcGIS Engine C#实例开发教程.pdf
C#程序100实例.rar
此实例包含了多个C#语言中Engine的开发实例代码。