Hello, I have created the profile of a 2D image. Now I want to move the picturebox ( which graphics the profile) along the penline inside the 2D image picturebox.
Thanks. and below is the codes that i have used.
public FrmProfile()
{
InitializeComponent();int xmid = pictureBox1.Width / 2;
xLines =new int[] { xmid };
}
private Pen pen1 = new Pen(Color.Blue,2);
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{bool yline = false;
pictureBox4.Cursor =
Cursors.SizeWE;
int xminDistance = int.MaxValue;
int xSelectedLineIndex = 0;
for (int u = 0; u < xLines.Length; u++)
int dist = Math.Abs(e.X - xLines[u]);
if (dist < xminDistance)
xminDistance = dist;
xSelectedLineIndex = u;
selectedLineIndex = xSelectedLineIndex;
yline = false;
void pictureBox1_MouseMove(object sender, MouseEventArgs e)
pictureBox1.Cursor =
if ((MouseButtons & MouseButtons.Left) != MouseButtons.Left)
return;
if (yline != true && e.X > 0 && e.X < 1534)
xLines[selectedLineIndex] = e.X;pictureBox1.Invalidate();
pictureBox2.Invalidate();
void pictureBox4_Paint(object sender, PaintEventArgs e)
foreach (int x in xLines)
e.Graphics.DrawLine(pen1, x, 0, x, pictureBox1.Height);