How to Implement the form drag-and-drop Function

Source: Internet
Author: User

In C/SProgram. The implementation of this function is as follows:

First, set to determine which control you want to drag the control to, find the control, and set the allowdrop attribute of the control to true, and then implement the two methods of the control, which are

Dragenter and dragdrop methods.

The dragenter method is as follows. In this example, the previous preprocessing is completed.

Private VoidDkpmain_dragenter (ObjectSender, drageventargs E)


If(E. Data. getdatapresent (dataformats. filedrop ))


E. effect = dragdropeffects. Move | dragdropeffects. Copy | dragdropeffects. Scroll;





E. effect = dragdropeffects. None;




The dragdrop method is mainly used to implement the drag-and-drop function. Here, we can use E. Data to obtain the drag-and-drop data.CodeAs follows:

Private VoidDkpmain_dragdrop (ObjectSender, drageventargs E)


If(E. Data. getdatapresent (dataformats. filedrop ))


String[] S = (String[]) E. Data. getdata (dataformats. filedrop );

This. _ Btmp =NewBitmap (s [0]);

This. Savefilename = s [0];

This. Pbfill. Image =This. _ Btmp;


In the code above, I am processing a drag-and-drop image. Through s [0], we can get all the paths of the drag-and-drop image. After knowing this path, other processing methods are the same as common ones.

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: 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.