المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Resize problem for drawn rectangle on the picture box?



C# Programming
08-13-2010, 10:11 AM
Hi,

Customer wants to draw a rectangle on the image and when zoom in and zoom out the position of the drawn rectangle should resize respectively.
Ex:
say a some text in the image and i have drawn a rectangle for that text. If i zoom the image the rectangle should also changes so they still covers that text on the image.

I don't want to paint (paste) the rectangle on the image because like to change the position the rectangle when ever user likes (i have achived this part so don't need ti wary on this)

I have load the image in the picture box and drawn some rectangles. Now like to zoom the image (along with drawn rectangle) as below code. My problem is when i zoom the image the Rectangle in the top of the image aligned correctly (at the new position) but the x point of the rectangle in the 3/4 (of the height of picture box)slightly move right.


How can resize the all rectangles?

Thanks in advance......

public void ZoomIn()
{


//sz to get the previous picture box size.
double ratio = 0d;

if (sz1.Width >= Convert.ToInt16(sz.Width * 2.2))
{
MessageBox.Show("Max ZoomIn");


}
else {

sz1.Width += 50;
sz1.Height += 50;
ratio = Convert.ToDouble(sz1.Width) / Convert.ToDouble(pictureBox1.Width);
pictureBox1.Size = sz1;
// get the Image rectangle value to set the offset
PropertyInfo pInfo = pictureBox1.GetType().GetProperty("ImageRectangle",
System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance);

rect1 = (Rectangle)pInfo.GetValue(pictureBox1, null);

n2 = rect1.Y - n3;
n3 = rect1.Y;


Point pf = pictureBox1.********;
pf.Offset(-25, -n2);

pictureBox1.******** = pf;

for (c = 0; c