Hi all,
I know how to drag and drop an image from one control to another.
Code enough out there. It works fine, but I find the user interface a bit poor:'( I want my image to follow the mouse while held down.
Found nothing that serves my needs on the web, except sprites, obscure code and what all not.
After some (long) experimenting I came up with the following:
Make a new forms app with a picturebox with a picture and add these events:
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
//make MouseMove active
this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
PictureBox P = sender as PictureBox;
P.Location = new Point(P.Location.X + e.Location.X, P.Location.Y + e.Location.Y);
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
//Deactivate MouseMove,
//used this one also to start off in the forms constructor after InitializeComponent
this.pictureBox1.MouseMove -= new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
}
This moves my picture, but I want to move a copy of the original and don't seem able to get that done. So any help or suggestion is more then welcome. Thanks in advance.