Пример #1
0
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            // NOTE: This Bitmap and Region work is done to workaround
            // the performance issues causes by using BackColor = Color.Transparent,
            // which would allow the exact functionality we want, but which is very
            // slow when the window is big or maximized.
            int width = Width, height = Height;

            if (width > 0 && height > 0)
            {
                // Update the boundaries of the control so we only draw within our own area
                int arcSize = (int)(width / 14.5);
                if (Region != null)
                {
                    Region.Dispose();
                    Region = null;
                }
                using (GraphicsPath path = GraphicsHelpers.CreateRoundedRectangle(width, height, arcSize))
                {
                    Region = new Region(path);
                }

                // Update the background underlying image to be rendered under
                // the sprites
                if (_underImage != null)
                {
                    _underImage.Dispose();
                }
                _underImage = new Bitmap(width, height, PixelFormat.Format32bppPArgb);
                using (Graphics g = Graphics.FromImage(_underImage))
                {
                    _grid.DrawToGraphics(g, _grid.ClientRectangle);
                    using (SolidBrush b = new SolidBrush(Color.FromArgb(128, Color.SlateGray)))
                    {
                        g.FillRectangle(b, ClientRectangle);
                    }
                }
            }
        }