How to drag a picturebox inside a panel control?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven Garrad

    How to drag a picturebox inside a panel control?

    Hi All,
    I have a pictureBox control inside of a panel control. The pictureBox is
    larger than the panel control and I have the panel control set true for
    AutoScroll so the panel displays scrolling bars.

    I would like the user to be able to click and drag the image and for it to
    move around within the panel control.

    How would I do this?

    Cheers,
    Steve
  • Alex Meleta

    #2
    Re: How to drag a picturebox inside a panel control?

    Steve,

    The simple way to just move the picture by clicking is:

    // Define a location before move
    int x;
    int y;

    // Storing begin point (by the left click)
    void pictureBox_Mous eDown(object sender, MouseEventArgs e) {
    if (e.Button == MouseButtons.Le ft) {
    x = e.X;
    y = e.Y;
    } }

    // Moving the picture
    void pictureBox_Mous eMove(object sender, MouseEventArgs e) {
    if (e.Button == MouseButtons.Le ft) {
    pictureBox1.Lef t += (e.X - x);
    pictureBox1.Top += (e.Y - y);
    } }

    Alex




    Hi All,
    I have a pictureBox control inside of a panel control. The pictureBox
    is
    larger than the panel control and I have the panel control set true
    for
    AutoScroll so the panel displays scrolling bars.
    I would like the user to be able to click and drag the image and for
    it to move around within the panel control.
    >
    How would I do this?
    >
    Cheers,
    Steve

    Comment

    Working...