Drag and drop operations

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I put two picture boxes on my main form. I was not able
to drag and drop on any of them. Also, the AllowDrop
property is not available at design time for the picture
box.
Any advice on an easy way to implement drag and drop for
picture boxes?

Thanks
Edi.
 
Hi,

Drag and drop for picture boxes works as expected, the only caveat as you
discovered is that the AllowDrop property is not available in the designer.
But you can quite happily set it in code. Then it is a matter of responding
to the relevant events.

Below is a very brief start as to handling the events, please excuse any
errors, I did not have the dev environment up to test this.

void PictureBox1_MouseDown( object sender, MouseEventArgs e )
{
DoDragDrop( PictureBox1.Image, DragDropEffects.All );
}

void PictureBox1_DragDrop( object sender, DragEventArgs e )
{
if ( e.Data.GetDataPresent( DataFormats.Bitmap ) )
{
PictureBox1.Image = e.Data.GetData( DataFormats.Bitmap );
}
}

void PictureBox1_DragEnter( object sender, DragEventArgs e )
{
if ( e.Data.GetDataPresent( DataFormats.Bitmap ) )
{
e.Effect = DragDropEffects.Copy;
}
}

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top