Moving an image in C#
I'm using Visual C# and im trying to move a picture box around the field using Mousedown and Mousemove but they are not working...>.>
Anyone have an idea of what the code may look like? I think somethings really wrong with mine.

Ben25 reputationPosted Sep 3, 2009, 1:27 PM EDT
private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { this.pictureBox1.Top += e.Y - this.positionCurseurImage.Y; this.pictureBox1.Left += e.X - this.positionCurseurImage.X; } } private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { if (!isPositionCurseurImageSet) this.positionCurseurImage = this.pictureBox1.PointToClient(Cursor.Position); isPositionCurseurImageSet = true; } private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { isPositionCurseurImageSet = false; }You need to declare a boolean to use as a flag, and a point to register the position of the mouse when you press the button compared to the topLeft of the image. In the MOUSEDOWN EVENT you save the position of the mouse, in the MOUSEMOVE EVENT if the left button is pressed, you move the picturbox. In the MOUSEUP EVENT you set your flag back to false.
Hope it helps with your problem.
Roei BarRank #1,271 · 1.4K reputationPosted Sep 3, 2009, 1:13 PM EDT
are you trying todo a drag and drop
if so here is a nice post on howto do that
http://www.java2s.com/Code/CSharp/GUI-Windows-Form/DraganddropthePictureBox.htm
hope this helps
shena forga7 reputationPosted Sep 4, 2009, 9:16 AM EDT