Exemplo n.º 1
0
        protected override void OnSizeChanged(EventArgs e)
        {
            VirtualDevice device = Device;

            if (device != null)
            {
                float xScale = 1;
                float yScale = 1;
                float ppd    = OffscreenGraphics.PixelsPerDip;

                CefRect viewportRect = device.ViewportRect;
                viewportRect.Scale(OffscreenGraphics.PixelsPerDip);
                Rectangle clientRect = this.ClientRectangle;
                if (viewportRect.Height > clientRect.Height)
                {
                    yScale = Math.Max(clientRect.Height - 6.0f, 1.0f) / viewportRect.Height;
                }

                if (viewportRect.Width > clientRect.Width)
                {
                    xScale = Math.Max(clientRect.Width - 6.0f, 1.0f) / viewportRect.Width;
                }

                device.Scale = Math.Min(xScale, yScale);

                CefRect bounds = device.GetBounds(ppd);
                device.X = (int)(((clientRect.Width - bounds.Width) >> 1) / ppd);
                device.Y = (int)(((clientRect.Height - bounds.Height) >> 1) / ppd);

                CefInvalidate();
            }

            base.OnSizeChanged(e);
        }
Exemplo n.º 2
0
        protected CefRect GetViewportRect()
        {
            CefRect       viewportRect;
            VirtualDevice device = Device;

            if (device == null)
            {
                viewportRect = new CefRect(0, 0, this.Width, this.Height);
                viewportRect.Scale(OffscreenGraphics.PixelsPerDip);
                return(viewportRect);
            }
            else
            {
                return(device.GetBounds(OffscreenGraphics.PixelsPerDip));
            }
        }