# question

## m0ve from point to another point

Hello there. I have a picture. When I click with mouse I get the x1 and y1 coordinates. The second time I click, I get the x2 and y2 coordinates. I want to move the picture from the first point to the second point. I want to change the x1 point of the picture to x2.

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I think I see what you're trying to do. Your picturebox click handler is storing the left point when the user left clicks and the right point when the user right clicks. Then when the button is clicked you are moving the pixels between the bounding box defined by those 2 points but into a second picture box. An interesting approach but let's solve the problem that you have.

I believe your picturebox click logic is fine so I'm ignoring that. However I still believe you're missing some information here. You are identifying the bounding box in PB1 with the left/right mouse clicks but you aren't specifying where inside PB2 to draw the new image. Here's the logic of your algorithm.

1. Get the width and height of the source image.

2. Get the starting point and the offset to use. Hence if the user selects starting point (10,20) and then clicks point (40, 30) then the image is being shifted over 40 and down 30 starting with point (10, 20) until the end of the image.

Based upon your original post it sounds like what you are trying to do is move the entire image, not from the starting point on. Thus your starting point is really just a reference point on the first image and the second click is used to get the offset that you want to move the image. Is that a correct assessment of what you want?

If so then your button click just needs to get the offset given the first and second points. Then apply the offset to every pixel in the original image to move the entire image the given offset. Since you're using a picturebox here you can actually just adjust the padding of the image based upon the offset to get it to render in the second control correctly. Of course if you actually wanted to change the image then it would require you transforming the image.

``````private void button1_Click ( object sender, EventArgs e )
{
int x2 = Convert.ToInt32(textBox1.Text);
int y2 = Convert.ToInt32(textBox2.Text);

int Tx = Convert.ToInt32(textBox3.Text);
int Ty = Convert.ToInt32(textBox4.Text);

//Get the offset from the first and second points
int offsetX = Tx - x2;
int offsetY = Ty - y2;

//Create a new image of the same size as the original image
var source = pictureBox1.Image;
var target = new Bitmap(source);

//Use padding to offset the original image in the control
pictureBox2.Image = target;
}``````

· 1

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you very much for your valuable comment. Finally someone who understood me came out. I literally want something like this. Bro I talked to about 10 people and nobody understood exactly what I wanted. Thank you for taking your time and explaining it so well. You are number one :)

Edit:
I managed to run the code clearly. It was a good development for my project thanks :)

To move a control programmatically at runtime set the control's Location property.

``pictureBox2.Location = E.Location;``

Note that this is a non-standard approach to moving a control and requires that you track mouse clicks inside and outside the picture box. A better approach might be to implement it via mouse drag. When the user left click holds the mouse over the picturebox you enter drag mode. When they release the mouse then you move the control to the new location. Of course you can go for a full drag and drop implementation as well.

· 3

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for your answer. But i don't want to carry the picturebox. I want to move the image in the picturebox.