本程序功能需要 PastePicture.dll 文件的支持,下载地址为:http://download.csdn.net/detail/jsjyyjs07/8907405
1.程序设计界面如下图:
操作方式为:按住快捷键Ctrl+V,鼠标点击一个PictureBox 完成图片的粘贴
按住快捷键Ctrl+C,鼠标点击一个PictureBox完成图片的复制
2.主要功能性代码如下:
using PastePicture;
ClipboardImage cImg = new ClipboardImage();
///
/// 监视Windows消息
/// 重载WndProc方法,用于实现热键响应
///
///
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
protected override void WndProc(ref Message m)
{
const int WM_HOTKEY = 0x0312;
//按快捷键
switch (m.Msg)
{
case WM_HOTKEY:
switch (m.WParam.ToInt32())
{
case 103:
//复制图片
cImg.CopyPictureToPictureBox(pictureBox, pictureBox1, pictureBox2, pictureBox3);
break;
case 104:
//粘贴图片
cImg.PastePictureToPictureBox(pictureBox, pictureBox1, pictureBox2, pictureBox3);
break;
}
break;
}
base.WndProc(ref m);
}
private void Form1_Activated(object sender, EventArgs e)
{
//注册快捷键 Ctrl+C,Ctrl+V
cImg.RegisterShortcuts(this);
}
private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
//释放快捷键 Ctrl+C,Ctrl+V
cImg.UnregisterShortcuts(this);
}
附 PastePicture.dll 注册快捷键代码如下:
///
/// 注册快捷键Ctrl+C,Ctrl+V
///
/// 窗体
public void RegisterShortcuts(Form form)
{
//注册Ctrl+C快捷键
UnsafeNativeMethods.RegisterHotKey(form.Handle, 103, 2, Keys.C);
//注册Ctrl+V快捷键
UnsafeNativeMethods.RegisterHotKey(form.Handle, 104, 2, Keys.V);
}
///
/// 释放快捷键Ctrl+C,Ctrl+V
///
/// 窗体
public void UnregisterShortcuts(Form form)
{
//释放Ctrl+C快捷键
UnsafeNativeMethods.UnregisterHotKey(form.Handle, 103);
//释放Ctrl+V快捷键
UnsafeNativeMethods.UnregisterHotKey(form.Handle, 104);
}
本程序功能实现很简单,大家可以尝试去自己写 PastePicture.dll中的代码,可以从本文章开始的地方下载该dll文件 进行反编译查看里面的代码。