I'm currently making a program to drawn lines by coordinates and the lines can be edited or moved. For now if want to move or edit the line, the cursor location will be the new A or B point. so moving the line is only possible by dragging the edge. Is there any method to make it possible to drag it by the body?
For the lines I'm using
Graphics g = e.Graphics;
Pen pen1 = new Pen(Color.Black, 3);
g.DrawLine(pen1, line1X1, line1Y1, line1X2, line1Y2);
pen1.Dispose();
and for the edge calculation in mousemove event right now I`m using
int oldX1 = line1X1; //Saving old coordinates for calculation
int oldY1 = line1Y1;
int oldX2 = line1X2;
int oldY2 = line1Y2;
int newX1 = e.Location.X; //New coordinates for calculation
int newY1 = e.Location.Y;
int difX = newX1 - oldX1; //Calculate the difference between old & new coordinates
int difY = newY1 - oldY1;
line1X1 = e.Location.X; //Move point 1 coordinates to new one
line1Y1 = e.Location.Y;
line1X2 = oldX2 + difX; //Move point 2 coordinates to old point 2 + difference
line1Y2 = oldY2 + difY;
x1Box.Text = line1X1.ToString();
y1Box.Text = line1Y1.ToString();
x2Box.Text = line1X2.ToString();
y2Box.Text = line1Y2.ToString();
tried to make 2nd calculation in mousemove event for click & drag anywhere on the screen to move but its not moving at all. if changed the calculation a bit it moved but shaking weirdly to both sides of the cursor example top & bottom of the cursor with same distance or left & right and keep swapping places when moving the cursor.
int clickPointX = e.Location.X;
int clickPointY = e.Location.Y;
int oldX1 = line1X1;
int oldY1 = line1Y1;
int difX = clickPointX - oldX1;
int difY = clickPointY - oldY1;
int dif1to2X = line1X2 - oldX1;
int dif1to2Y = line1Y2 - oldY1;
line1X1 = clickPointX - difX;
line1Y1 = clickPointY - difY;
line1X2 = line1X1 + dif1to2X;
line1Y2 = line1Y1 + dif1to2Y;
x1Box.Text = line1X1.ToString();
y1Box.Text = line1Y1.ToString();
x2Box.Text = line1X2.ToString();
y2Box.Text = line1Y2.ToString();
application image
Question is.
Anyone know how to move the line by clicking & dragging the body not the edge?
Anyone know what is wrong with my 2nd calculation to move the line by click & drag anywhere?
Thank you very much