This program function needs PastePicture.dll file support, for: http://download.csdn.net/detail/jsjyyjs07/8907405
1. Programming interface such as:
Operation is: Press and hold the shortcut key Ctrl + V, the mouse click on a PictureBox to complete the image paste
Press and hold the shortcut key CTRL + C, mouse click on a PictureBox to complete the image copy
2. The main functional code is as follows:
Using Pastepicture;
Clipboardimage cImg = new Clipboardimage ();
<summary>
Monitoring Windows messages
Overloaded WndProc method for implementing Hotkey responses
</summary>
<param name= "M" ></param>
[SecurityPermission (SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
protected override void WndProc (ref Message m)
{
const int wm_hotkey = 0x0312;
Press the shortcut key
Switch (m.msg)
{
Case Wm_hotkey:
Switch (M.wparam.toint32 ())
{
Case 103:
Copy Picture
Cimg.copypicturetopicturebox (PictureBox, PictureBox1, PictureBox2, PictureBox3);
Break
Case 104:
Paste Picture
Cimg.pastepicturetopicturebox (PictureBox, PictureBox1, PictureBox2, PictureBox3);
Break
}
Break
}
Base. WndProc (ref m);
}
private void Form1_activated (object sender, EventArgs e)
{
Register shortcut Keys Ctrl+c,ctrl+v
Cimg.registershortcuts (this);
}
private void Main_formclosing (object sender, FormClosingEventArgs e)
{
Releasing shortcut keys Ctrl+c,ctrl+v
Cimg.unregistershortcuts (this);
}
Attached PastePicture.dll Registration shortcut code is as follows:
//<summary>
//Register shortcut Ctrl+c,ctrl+v
//</summary>
//<param name= " Form "> Forms </param>
public void registershortcuts (Form form)
{
//Register CTRL + C shortcut key
Unsafenativemethods.registerhotkey (form. Handle, 103, 2, KEYS.C);
//Register CTRL + V shortcut keys
Unsafenativemethods.registerhotkey (form. Handle, 104, 2, KEYS.V);
}
//<summary>
/ Release shortcut keys Ctrl+c,ctrl+v
//</summary>
//<param name= "form" > Form </param>
public void unregistershortcuts (Form form)
{
//Release CTRL + C shortcut keys
Unsafenativemethods.unregisterhotkey (form. Handle, 103);
//Release CTRL + V shortcut keys
Unsafenativemethods.unregisterhotkey (form. Handle, 104);
}
The implementation of this program is very simple, you can try to write your own code in PastePicture.dll, you can download the DLL file from the beginning of this article to decompile to see the code inside.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C # WinForm implements pictures pasted into PictureBox and copied PictureBox