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;
}
Else
{
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.