Exemplo n.º 1
0
        bool CalcaluteImageViewSize()
        {
            if (Image != null)
            {
                var size       = Image.Size;
                var clientSize = ClientSize;
                var zoom       = Zoom;
                switch (ZoomType)
                {
                case ZoomType.FitHeight:
                    zoom = (float)clientSize.Height / size.Height;
                    if (zoom * size.Width > clientSize.Width)
                    {
                        zoom = (float)(clientSize.Height - SystemInformation.HorizontalScrollBarHeight) / size.Height;
                    }
                    break;

                case ZoomType.FitWidth:
                    zoom = (float)clientSize.Width / size.Width;
                    if (zoom * size.Height > clientSize.Height)
                    {
                        zoom = (float)(clientSize.Width - SystemInformation.VerticalScrollBarWidth) / size.Width;
                    }
                    break;

                case ZoomType.FitPage:
                    zoom = Math.Min((float)clientSize.Width / size.Width, (float)clientSize.Height / size.Height);
                    break;
                }

                ZoomValue = zoom;
                size      = PaintHelper.Zoom(size, zoom);
                if (ImageViewSize != size)
                {
                    ImageViewSize     = size;
                    AutoScrollMinSize = ImageViewSize;
                    return(true);
                }
            }

            return(false);
        }