Exemplo n.º 1
0
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            // This code fixes the size of the surfaceBox as necessary to
            // maintain the aspect ratio of the surface. Keeping the mouse
            // within 32767 is delegated to the new overflow-checking code
            // in Tool.cs.

            Size mySize = this.Size;

            if (this.Width == MaxSideLength && _surface != null)
            {
                // Windows forms probably clamped this control's width, so we have to fix the height.
                mySize.Height = (int)(((long)(MaxSideLength + 1) * (long)_surface.Height) / (long)_surface.Width);
            }
            else if (mySize.Width == 0)
            {
                mySize.Width = 1;
            }

            if (this.Width == MaxSideLength && _surface != null)
            {
                // Windows forms probably clamped this control's height, so we have to fix the width.
                mySize.Width = (int)(((long)(MaxSideLength + 1) * (long)_surface.Width) / (long)_surface.Height);
            }
            else if (mySize.Height == 0)
            {
                mySize.Height = 1;
            }

            if (mySize != this.Size)
            {
                this.Size = mySize;
            }

            if (_surface == null)
            {
                this._scaleFactor = ScaleFactor.OneToOne;
            }
            else
            {
                ScaleFactor newSF = ScaleFactor.Max(this.Width, _surface.Width,
                                                    this.Height, _surface.Height,
                                                    ScaleFactor.OneToOne);

                this._scaleFactor = newSF;
            }

            this._rendererList.DestinationSize = this.Size;
        }