public override void RenderRightToggleField(Graphics g, Rectangle rightRectangle, int totalToggleFieldWidth)
        {
            Color rightColour = RightSideColour;

            KryptonToggleSwitch toggleSwitch = new KryptonToggleSwitch();

            if (!toggleSwitch.Enabled && toggleSwitch.GrayWhenDisabled)
            {
                rightColour = rightColour.ToGrayScale();
            }

            Rectangle controlRectangle = GetInnerControlRectangle();

            g.SetClip(controlRectangle);

            int halfCathetusLength = GetHalfCathetusLengthBasedOnAngle();

            Rectangle adjustedRightRect = new Rectangle(rightRectangle.X - halfCathetusLength, rightRectangle.Y, rightRectangle.Width + halfCathetusLength, rightRectangle.Height);

            g.IntersectClip(adjustedRightRect);

            using (Brush rightBrush = new SolidBrush(rightColour))
            {
                g.FillRectangle(rightBrush, adjustedRightRect);
            }

            g.ResetClip();
        }
        public override Rectangle GetButtonRectangle(int buttonWidth)
        {
            KryptonToggleSwitch toggleSwitch = new KryptonToggleSwitch();

            Rectangle buttonRect = new Rectangle(toggleSwitch.ButtonValue, 0, buttonWidth, toggleSwitch.Height);

            return(buttonRect);
        }
        public override void RenderBorder(Graphics g, Rectangle borderRectangle)
        {
            KryptonToggleSwitch toggleSwitch = new KryptonToggleSwitch();

            Color borderColour = !toggleSwitch.Enabled && toggleSwitch.GrayWhenDisabled ? BorderColour.ToGrayScale() : BorderColour;

            g.SetClip(borderRectangle);

            using (Pen borderPen = new Pen(borderColour))
            {
                g.DrawRectangle(borderPen, borderRectangle.X, borderRectangle.Y, borderRectangle.Width - 1, borderRectangle.Height - 1);
            }
        }
 internal void SetToggleSwitch(KryptonToggleSwitch toggleSwitch)
 {
     _toggleSwitch = toggleSwitch;
 }
        public override void RenderButton(Graphics g, Rectangle buttonRectangle)
        {
            Rectangle controlRectangle = GetInnerControlRectangle();

            g.SetClip(controlRectangle);

            int fullCathetusLength    = GetCathetusLengthBasedOnAngle();
            int dblFullCathetusLength = 2 * fullCathetusLength;

            KryptonToggleSwitch toggleSwitch = new KryptonToggleSwitch();

            Point[] polygonPoints = new Point[4];

            Rectangle adjustedButtonRect = new Rectangle(buttonRectangle.X - fullCathetusLength, controlRectangle.Y, buttonRectangle.Width + dblFullCathetusLength, controlRectangle.Height);

            if (SlantAngle > 0)
            {
                polygonPoints[0] = new Point(adjustedButtonRect.X + fullCathetusLength, adjustedButtonRect.Y);
                polygonPoints[1] = new Point(adjustedButtonRect.X + adjustedButtonRect.Width - 1, adjustedButtonRect.Y);
                polygonPoints[2] = new Point(adjustedButtonRect.X + adjustedButtonRect.Width - fullCathetusLength - 1, adjustedButtonRect.Y + adjustedButtonRect.Height - 1);
                polygonPoints[3] = new Point(adjustedButtonRect.X, adjustedButtonRect.Y + adjustedButtonRect.Height - 1);
            }
            else
            {
                polygonPoints[0] = new Point(adjustedButtonRect.X, adjustedButtonRect.Y);
                polygonPoints[1] = new Point(adjustedButtonRect.X + adjustedButtonRect.Width - fullCathetusLength - 1, adjustedButtonRect.Y);
                polygonPoints[2] = new Point(adjustedButtonRect.X + adjustedButtonRect.Width - 1, adjustedButtonRect.Y + adjustedButtonRect.Height - 1);
                polygonPoints[3] = new Point(adjustedButtonRect.X + fullCathetusLength, adjustedButtonRect.Y + adjustedButtonRect.Height - 1);
            }

            g.IntersectClip(adjustedButtonRect);

            Color buttonColour       = toggleSwitch.Checked ? OnButtonColour : OffButtonColour;
            Color buttonBorderColour = toggleSwitch.Checked ? OnButtonBorderColour : OffButtonBorderColour;

            if (!toggleSwitch.Enabled && toggleSwitch.GrayWhenDisabled)
            {
                buttonColour       = buttonColour.ToGrayScale();
                buttonBorderColour = buttonBorderColour.ToGrayScale();
            }

            using (Pen buttonPen = new Pen(buttonBorderColour))
            {
                g.DrawPolygon(buttonPen, polygonPoints);
            }

            using (Brush buttonBrush = new SolidBrush(buttonColour))
            {
                g.FillPolygon(buttonBrush, polygonPoints);
            }

            Image  buttonImage = toggleSwitch.ButtonImage ?? (toggleSwitch.Checked ? toggleSwitch.OnButtonImage : toggleSwitch.OffButtonImage);
            string buttonText  = toggleSwitch.Checked ? toggleSwitch.OnText : toggleSwitch.OffText;

            if (buttonImage != null || !string.IsNullOrEmpty(buttonText))
            {
                ToggleSwitchButtonAlignment alignment = toggleSwitch.ButtonImage != null ? toggleSwitch.ButtonAlignment : (toggleSwitch.Checked ? toggleSwitch.OnButtonAlignment : toggleSwitch.OffButtonAlignment);

                if (buttonImage != null)
                {
                    Size      imageSize = buttonImage.Size;
                    Rectangle imageRectangle;

                    int imageXPos = (int)adjustedButtonRect.X;

                    bool scaleImage = toggleSwitch.ButtonImage != null ? toggleSwitch.ButtonScaleImageToFit : (toggleSwitch.Checked ? toggleSwitch.OnButtonScaleImageToFit : toggleSwitch.OffButtonScaleImageToFit);

                    if (scaleImage)
                    {
                        Size canvasSize       = adjustedButtonRect.Size;
                        Size resizedImageSize = KryptonToggleSwitchImageHelper.RescaleImageToFit(imageSize, canvasSize);

                        if (alignment == ToggleSwitchButtonAlignment.Center)
                        {
                            imageXPos = (int)((float)adjustedButtonRect.X + (((float)adjustedButtonRect.Width - (float)resizedImageSize.Width) / 2));
                        }
                        else if (alignment == ToggleSwitchButtonAlignment.Right)
                        {
                            imageXPos = (int)((float)adjustedButtonRect.X + (float)adjustedButtonRect.Width - (float)resizedImageSize.Width);
                        }

                        imageRectangle = new Rectangle(imageXPos, (int)((float)adjustedButtonRect.Y + (((float)adjustedButtonRect.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);

                        if (!toggleSwitch.Enabled && toggleSwitch.GrayWhenDisabled)
                        {
                            g.DrawImage(buttonImage, imageRectangle, 0, 0, buttonImage.Width, buttonImage.Height, GraphicsUnit.Pixel, KryptonToggleSwitchImageHelper.GetGrayscaleAttributes());
                        }
                        else
                        {
                            g.DrawImage(buttonImage, imageRectangle);
                        }
                    }
                    else
                    {
                        if (alignment == ToggleSwitchButtonAlignment.Center)
                        {
                            imageXPos = (int)((float)adjustedButtonRect.X + (((float)adjustedButtonRect.Width - (float)imageSize.Width) / 2));
                        }
                        else if (alignment == ToggleSwitchButtonAlignment.Right)
                        {
                            imageXPos = (int)((float)adjustedButtonRect.X + (float)adjustedButtonRect.Width - (float)imageSize.Width);
                        }

                        imageRectangle = new Rectangle(imageXPos, (int)((float)adjustedButtonRect.Y + (((float)adjustedButtonRect.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);

                        if (!toggleSwitch.Enabled && toggleSwitch.GrayWhenDisabled)
                        {
                            g.DrawImage(buttonImage, imageRectangle, 0, 0, buttonImage.Width, buttonImage.Height, GraphicsUnit.Pixel, KryptonToggleSwitchImageHelper.GetGrayscaleAttributes());
                        }
                        else
                        {
                            g.DrawImageUnscaled(buttonImage, imageRectangle);
                        }
                    }
                }
                else if (!string.IsNullOrEmpty(buttonText))
                {
                    Font  buttonFont      = toggleSwitch.Checked ? toggleSwitch.OnFont : toggleSwitch.OffFont;
                    Color buttonForeColor = toggleSwitch.Checked ? toggleSwitch.OnForeColour : toggleSwitch.OffForeColour;

                    if (!toggleSwitch.Enabled && toggleSwitch.GrayWhenDisabled)
                    {
                        buttonForeColor = buttonForeColor.ToGrayScale();
                    }

                    SizeF textSize = g.MeasureString(buttonText, buttonFont);

                    float textXPos = adjustedButtonRect.X;

                    if (alignment == ToggleSwitchButtonAlignment.Center)
                    {
                        textXPos = (float)adjustedButtonRect.X + (((float)adjustedButtonRect.Width - (float)textSize.Width) / 2);
                    }
                    else if (alignment == ToggleSwitchButtonAlignment.Right)
                    {
                        textXPos = (float)adjustedButtonRect.X + (float)adjustedButtonRect.Width - (float)textSize.Width;
                    }

                    RectangleF textRectangle = new RectangleF(textXPos, (float)adjustedButtonRect.Y + (((float)adjustedButtonRect.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);

                    using (Brush textBrush = new SolidBrush(buttonForeColor))
                    {
                        g.DrawString(buttonText, buttonFont, textBrush, textRectangle);
                    }
                }
            }

            g.ResetClip();
        }