picture moving


  • Hi all.I have a problem.I have a panel and a picturebox(a picture within a box) in c# and i want to move the picture or picturebox when i press and hold down the mouse button in the border of the panel or picturebox.Please,if anyone have a godd idea,or code,please help me.thx
    Tuesday, October 19, 2010 7:53 AM


All replies

  • Simply increment or decrement the right property of the picturebox as long as its value is more then zero and less than the panel.width minus the picturebox.width

    If you want it done while keeping the mouse button down, then start a timer and do the move in the timer using the mouse down event and stop the timer based on the mouse up event.

    Quite easy to do. 


    Tuesday, October 19, 2010 8:18 AM
  • you can do this by 

    private void Form2_MouseMove(object sender, MouseEventArgs e)


                pictureBox1.Location = new Point(e.X, e.Y);


    Tuesday, October 19, 2010 8:55 AM
  • Have a look here:

    Do what's in the eventhandlers for panel1 there, in your PictureBox' MouseDown/Move/Up events.



    • Proposed as answer by Helen Zhou Monday, October 25, 2010 7:14 AM
    • Marked as answer by Helen Zhou Tuesday, October 26, 2010 8:37 AM
    Wednesday, October 20, 2010 12:59 AM