I\'m moving control(label or image) success in PictureBox. When I move, it will save control position(x, y).
Like this:
But problem is: the image re
If your PictureBox
is in Sizemodes
StretchImage
or Zoom
then the pixels are scaled; the Label
's Location
however is not. So you would have the calculate the position where to draw:
PointF stretched(Point p0, PictureBox pb)
{
if (pb.Image == null) return PointF.Empty;
float scaleX = 1f * pb.Image.Width / pb.ClientSize.Width;
float scaleY = 1f * pb.Image.Height / pb.ClientSize.Height;
return new PointF(p0.X * scaleX, p0.Y * scaleY);
}
You would call it as PointF p1 = stretched(p0, pictureBox1);
You would draw maybe like this:
g.DrawImage( DrawText(image, new Font(cbxFont.Text, fontSize),
colorInput, Color.Transparent),
Point.Round(stretched( CtrlPos.Location, picPreview));
If you also want to correct the size you can use a similar function..
If the SizeMode
is CenterImage
the pixels are not scaled but most likely transposed and a correction is necessary as well.
For the other direction simply switch denominator and numerator in the fractions!