Hi,


Have drawn rectangle and zoom the image. As per zoom, the rectangle are redrawn (http://www.daniweb.com/forums/thread296495.html). Redrawn rectangle place slightly down. so i adjusted to fit the point. but the rectangle value varies with different resolutions.

how to adjust the rectangle value with different resolution.

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)

{



if (mybitmap == null)

{

mybitmap = new Bitmap(pictureBox1.Image.Width, pictureBox1.Image.Height);

mybitmap.SetResolution(300, 300);

}



rect = new Rectangle(e.X, e.Y, 0, 0);

pictureBox1.Invalidate();



}

private void pictureBox1_Paint(object sender, PaintEventArgs e)

{


if (mybitmap == null)

{

return;

}



using (Pen pen = new Pen(Color.Green, 2))

{


foreach (Rectangle r in rectangles)

{

e.Graphics.DrawRectangle(pen, r);

 

e.Graphics.DrawString(lab[c].ToString(), new Font(lab[c].ToString(), 8F), new SolidBrush(label1.ForeColor), r);


}

 }

 
}


//sz1 = pic width, sz = form width
public void ZoomIn()
            {
                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;
                   

//Image rectangle value in Non-Public members increases when pic width increases, so i used this value to adjust the picture location to stay top (this works with different resolution).

                        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 to hold previous value of image rectangle
                        n3 = rect1.Y;

                        Point pf = pictureBox1.Location;
                        pf.Offset(-25, -n2);
                        if ((pf.Y < 0))
                        {
                          pf.Offset(0, 0);
                        }
                            pictureBox1.Location = pf;
                        

//the below code works fine if the resolution is 1152*864
                    for (c=0; c <= (rectangles.Count-1); c++)
                    {

                        rect1.X = Convert.ToInt16((rectangles[c].X) * ratio)


// used n2 to adjust the position
                        if (sz1.Width < (sz.Width + (50 * 8)))
                        
                        rect1.Y = Convert.ToInt16((rectangles[c].Y * ratio))+(n2-1);
                       
                    else if (sz1.Width < (sz.Width+(50*10)))
                    rect1.Y = Convert.ToInt16((rectangles[c].Y * ratio)) + (n2-2);
                        else if (sz1.Width < (sz.Width+(50*15)))
                            rect1.Y = Convert.ToInt16((rectangles[c].Y * ratio)) + (n2-3);

                        else if (sz1.Width < (sz.Width + (50 * 25)))
                            rect1.Y = Convert.ToInt16((rectangles[c].Y * ratio)) + (n2-4);
                        else
                            rect1.Y = Convert.ToInt16((rectangles[c].Y * ratio)) + (n2 -5);
                        
ratio)+5);
                        rect1.Width = Convert.ToInt16(rectangles[c].Width * ratio);
                        rect1.Height = Convert.ToInt16(rectangles[c].Height * ratio);
                        rectangles.RemoveAt(c);
                        rectangles.Insert(c, rect1);
                        
                    }
                   
                    
                
             
                   rect = new Rectangle(0, 0, 0, 0);
                    pictureBox1.Invalidate();
                }


            }

How to do this with different resolution.
note: don't know that what resolution will user use.

Note: this cede will dependable with sys resolution (not Generic)

switch (svc.Bounds.Width.ToString())
                    {
                           
                        case "800":
                            {
                               if (c == 290)
                                    d = -64;
                              else if (c == 326)
                                      d = -100;
                                else if (c == 363)
                                       d = -137;
                                else if (c == 409)
                                       d=-183;
                                 else
                                      d = 0;
                       diffscreenresolution(b, d);
                                break;
                            }

                        case "1024":
                            {
                               if (c == 226)
                                      d = 64;
                                else if (c == 326)
                                        d = -36;
                                 else if (c == 363)
                                         d = -73;
                                  else if (c == 409)
                                         d = -120;
                                   else
                                        d=0;
                         diffscreenresolution(b, d);
                                break;
                            }
                        case "1152":
                            {
                              if (c == 226)
                                     d = 100;
                              else if (c == 290)
                                      d = 36;
                               else if (c == 363)
                                       d = -37;
                                else if (c == 409)
                                       d = -83;
                                 else
                                      d = 0;
                         diffscreenresolution(b, d);
                                break;
                            }

                        case "1280":
                            {
                               if (c == 226)
                                        d = 137;
                                else if (c==290)
                                         d=73;
                                 else if (c==326)
                                         d=37;
                                  else if (c==409)
                                          d = -47;
                                   else
                                         d = 0;
                         diffscreenresolution(b, d);

                                break;

                            }
                        

                        
                        case "1440":
                            {
                              if (c == 226)
                                       d = 183;
                              else if (c==290)
                                       d = 120;
                               else if (c==326)
                                       d = 83;
                                else if (c==363)
                                       d = 47;
                                 else
                                      d = 0;
                        diffscreenresolution(b, d);
                                break;
                            }
                      

                        default:
                            {
                                d = 0;
                                break;
                            }
                    }

private void diffscreenresolution(int b1, int z)
        {

//width will same. no need to chage the width
rect.X = Convert.ToInt16(Convert.ToDouble(rect.X)) + z;
                    rect.Y = Convert.ToInt16((Convert.ToDouble(rect.Y) / Convert.ToDouble(b)) * (Convert.ToDouble((rect2.Height))));
                    rect.Height = Convert.ToInt16(Convert.ToDouble(rect.Height) * (Convert.ToDouble(rect2.Height) / Convert.ToDouble(b)));

}
This question has already been answered. Start a new discussion instead.