Quantcast
Channel: How to Move a PictureBox
Viewing all articles
Browse latest Browse all 11

How to Move a PictureBox

$
0
0

Hi, Im trying to move a picturebox in a panel by moving the mouse. Here is the code I'm using:

System.Drawing.Point p;
    bool move;

private void panel1_MouseDown(object sender, MouseEventArgs e)
    {
      p.X = e.X;
      p.Y = e.Y;
      move = true;
    }

    private void panel1_MouseMove(object sender, MouseEventArgs e)
    {
      if (move)
      {
        pictureBox1.Left += e.X - p.X;
      }
    }

    private void panel1_MouseUp(object sender, MouseEventArgs e)
    {
      move = false;
    }

Nevertheless it does not woek, the picturebox dissapears from the form. If I use the same code on the PictureBox events it works just fine, however I want to move the picturebox by clickin in any part of the form.

 

Thanks in advance

 


Viewing all articles
Browse latest Browse all 11

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>