What I want is to move the object and rotate along its center point. I've used Matrix class for transformation:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.ResetTransform();
Matrix transformationMatrix = new Matrix();
transformationMatrix.RotateAt(rot, new PointF(img.Size.Width / 2, img.Size.Height / 2));
e.Graphics.Transform = transformationMatrix;
e.Graphics.DrawImage(img, 0, 0, img.Size.Width, img.Size.Height);
}
Above code will rotate the image along its center.
But if I try to move it(I placed the image in the center of pictureBox), the image is no more rotating along it's center point.
e.Graphics.DrawImage(img, (pictureBox1.Width - img.Size.Width) / 2, (pictureBox1.Height - img.Size.Height) / 2, img.Size.Width, img.Size.Height);
Now I guess I have to use Translate function to specify position, but I have no clue how to do that. Translate takes relative position. I want to specify the image location using its center point and be able to rotate it along its center.
Update 2:
Modified code look like this
origin.X = 50;
origin.Y = 50;
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.TranslateTransform(origin.X, origin.Y);
e.Graphics.RotateTransform(rot);
e.Graphics.DrawImage(img, -img.Size.Width, -img.Size.Height/2, img.Size.Width, img.Size.Height);
}
So I defined Point origin to specify the location of my image. But still it doesn't rotate along its center.