C # WinForm implements pictures pasted into PictureBox and copied PictureBox

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.