Despite the fact that Nivas did not indicate what he wants to achieve, I suspect that it looks like what I just looked at - translating a rectangle with a drawing (i.e. I did not try to inherit, as suggested by RvdK, I used a reflection method as a quick workaround. An alternative to RvdK's suggestion or opening Microsoft to access ImageRectangle would be to provide a RectangleToImageRectangle method. Which I suppose I could wrap an object that inherits from PB ...
Disabled Microsoft Connect Issue link.
Here is the code I used, it provides a rectangle of the PB image and has been tested for .Zoom and .StretchImage modes:
PropertyInfo pInfo = pictureBox1.GetType().GetProperty("ImageRectangle", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); Rectangle ImRectangle = (Rectangle)pInfo.GetValue(pictureBox1, null); Point rTL = new Point((rectCropArea.Left - ImRectangle.Left) * pictureBox1.Image.Width / ImRectangle.Width, (rectCropArea.Top - ImRectangle.Top) * pictureBox1.Image.Height / ImRectangle.Height); Size rSz = new Size(pictureBox1.Image.Width * rectCropArea.Width / ImRectangle.Width, pictureBox1.Image.Height * rectCropArea.Height / ImRectangle.Height); 'rect' = new Rectangle(rTL,rSz);
mr23
source share