I want use DragDrop
in my PicureBox
es but DragDrop()
and DragEnter()
methods are never called.
I created method MouseMove
and in this method I called DoDragDrop()
which should call DragDrop()
and DragEnter()
. MouseMove
is called but rest not.
Form constructor:
public Form1()
{
InitializeComponent();
this.AllowDrop = true;
}
This is create in constructor of PictureBox
:
this.DragDrop += new DragEventHandler(ttile_DragDrop);
this.DragEnter += new DragEventHandler(ttile_DragEnter);
this.MouseMove += new MouseEventHandler(ttile_MouseMove);
And my method:
public void ttile_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
int i = 0;
}
public void ttile_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
int i = 0;
}
public void ttile_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
((PictureBox)sender).DoDragDrop(sender, DragDropEffects.All);
}
}
I had a similar issue. The problem is that you have AllowDrop
for the form, but not the picture. And for a reason I ignore, AllowDrop
is not a member of PictureBox
.
The trick that worked for me was to replace
this.AllowDrop = True;
by
((Control)myPictureBox).AllowDrop = True;
where myPictureBox
is my instance of PictureBox
.
myPictureBox.AllowDrop = true;
You can use this code though you won't see 'AllowDrop' in myPictureBox's method list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With