Animatroller.Simulator.Control.Bulb.LedBulb.drawControl C# (CSharp) Метод

drawControl() приватный Метод

Renders the control to an image
private drawControl ( Graphics g ) : void
g System.Drawing.Graphics
Результат void
        private void drawControl(Graphics g)
        {
            Color lightColor = (this.On) ? this.Color : this.DarkColor;
            Color darkColor = (this.On) ? this.DarkColor : this.DarkDarkColor;

            var paddedRectangle = new Rectangle(
                this.Padding.Left,
                this.Padding.Top,
                this.Width - (this.Padding.Left + this.Padding.Right) - 1,
                this.Height - (this.Padding.Top + this.Padding.Bottom) - 1);
            int width = (paddedRectangle.Width < paddedRectangle.Height) ? paddedRectangle.Width : paddedRectangle.Height;
            var drawRectangle = new Rectangle(paddedRectangle.X, paddedRectangle.Y, width, width);

            // Draw the background ellipse
            if (drawRectangle.Width < 1)
                drawRectangle.Width = 1;
            if (drawRectangle.Height < 1)
                drawRectangle.Height = 1;
            using (var darkSolidBrush = new SolidBrush(darkColor))
                g.FillEllipse(darkSolidBrush, drawRectangle);

            // Draw the glow gradient
            using (var path = new GraphicsPath())
            {
                path.AddEllipse(drawRectangle);
                using (var pathBrush = new PathGradientBrush(path))
                {
                    pathBrush.CenterColor = lightColor;
                    pathBrush.SurroundColors = new Color[] { Color.FromArgb(0, lightColor) };
                    g.FillEllipse(pathBrush, drawRectangle);
                }

                // Set the clip boundary  to the edge of the ellipse
                using (var gp = new GraphicsPath())
                {
                    gp.AddEllipse(drawRectangle);
                    g.SetClip(gp);
                }
                // Draw the white reflection gradient
                using (var path1 = new GraphicsPath())
                {
                    var whiteRect = new Rectangle(
                        drawRectangle.X - Convert.ToInt32(drawRectangle.Width * .15F),
                        drawRectangle.Y - Convert.ToInt32(drawRectangle.Width * .15F),
                        Convert.ToInt32(drawRectangle.Width * .8F),
                        Convert.ToInt32(drawRectangle.Height * .8F));
                    path1.AddEllipse(whiteRect);

                    using (var pathBrush1 = new PathGradientBrush(path))
                    {
                        pathBrush1.CenterColor = Color.FromArgb(180, 255, 255, 255);
                        pathBrush1.SurroundColors = new Color[] { Color.FromArgb(0, 255, 255, 255) };
                        g.FillEllipse(pathBrush1, whiteRect);
                    }
                }
            }

            // Draw the border
            float w = drawRectangle.Width;
            g.SetClip(this.ClientRectangle);
            if (this.On)
                g.DrawEllipse(new Pen(Color.FromArgb(85, Color.Black), 1F), drawRectangle);
        }