how to move graphics drawn on picture box on c sharp

Posted by Shanky11 under Windows Forms on 11/12/2013 | Points: 10 | Views : 3199 | Status : [Member] | Replies : 2
i draw a line on picture box
now i want to move it from one place to another
how can i do it????




Responses

Posted by: Rama Sagar on: 11/13/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
you can use this to move the graphics inside picture box by LarsTech

private Point startingPoint = Point.Empty;
private Point movingPoint = Point.Empty;
private bool panning = false;

void pictureBox1_MouseDown(object sender, MouseEventArgs e) {
panning = true;
startingPoint = new Point(e.Location.X - movingPoint.X,
e.Location.Y - movingPoint.Y);
}

void pictureBox1_MouseUp(object sender, MouseEventArgs e) {
panning = false;
}

void pictureBox1_MouseMove(object sender, MouseEventArgs e) {
if (panning) {
movingPoint = new Point(e.Location.X - startingPoint.X,
e.Location.Y - startingPoint.Y);
pictureBox1.Invalidate();
}
}

void pictureBox1_Paint(object sender, PaintEventArgs e) {
e.Graphics.Clear(Color.White);
e.Graphics.DrawImage(Image, movingPoint);
}

ramasagar

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 11/13/2013 [Member] Starter | Points: 25

Up
0
Down
i draw a line i need that line to move on picture box
there may be several lines.

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response