PDA

View Full Version : هنگام بازگشت از حالت زوم ، جای picturebox تغییر می کنه



نیکناز
دوشنبه 13 مرداد 1393, 07:18 صبح
سلام دوستان
من دو تا picture box دارم.
اولی شامل یک لوزی بزرگ ، و دومی شامل یک دایره کوچیک .
من باید این دایره رو روی راس های لوزی بزارم.
برای این کار چون جای دقیق راس اهمیت داره ، من لوزی رو زوم می کنم بعد دایره رو قرار می دم.
اما وقتی از حالت زوم بر می گردم به حالت عادی ، دیگه دایره اون جایی که قرار دادمش ، قرار نداره.
با برگشت از حالت زوم ، پیکسل دایره تغیر می کنه.
من باید چه کار کنم؟



protected override void OnMouseWheel(MouseEventArgs e)
{
this.Cursor = Cursors.Default;
float oldzoom = zoom;


if (e.Delta > 0)
{
zoom += 0.625f;
zoomPerectNum += 50;
_txt_precentZoom.Text = zoomPerectNum.ToString() + "%";
}


else if (e.Delta < 0)
{
// zoom = Math.Max(zoom - 1F, 1F);
zoom = zoom - 0.625F;


if (zoom < 0.2503874F)
{
zoom = 0.2503874F;
}
else
{
zoomPerectNum -= 50;
_txt_precentZoom.Text = zoomPerectNum.ToString() + "%";
}
}


MouseEventArgs mouse = e as MouseEventArgs;
Point mousePosNow = mouse.Location;


int x = mousePosNow.X - _pic_image.Location.X; // Where location of the mouse in the pictureframe
int y = mousePosNow.Y - _pic_image.Location.Y;


int oldimagex = (int)(x / oldzoom); // Where in the IMAGE is it now
int oldimagey = (int)(y / oldzoom);


int newimagex = (int)(x / zoom); // Where in the IMAGE will it be when the new zoom i made
int newimagey = (int)(y / zoom);


imgx = newimagex - oldimagex + imgx; // Where to move image to keep focus on one point
imgy = newimagey - oldimagey + imgy;


_pic_image.Refresh(); // calls imageBox_Paint
}


private void imageBox_Paint(object sender, PaintEventArgs e)
{
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
e.Graphics.ScaleTransform(zoom, zoom);




if (img != null)
{
e.Graphics.DrawImage(img, imgx, imgy);
}


}














private void _pic_Circle_MouseDown(object sender, MouseEventArgs e)
{
dragging = true;
dragPoint = new Point(e.X, e.Y);


}
private void _pic_Circle_MouseMove(object sender, MouseEventArgs e)
{
if (dragging)
{

_pic_Circle.Location = new Point(_pic_Circle.Location.X + e.X - dragPoint.X, _pic_Circle.Location.Y + e.Y - dragPoint.Y);
}
}



private void _pic_Circle_MouseUp(object sender, MouseEventArgs e)
{

dragging = false;
}