protected override void OnPaint(PaintEventArgs e) { e.Graphics.Clear(Parent.BackColor); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; // Отрисовка анимации Int32 X; if (Animation && RippleAnimationManager.IsAnimating()) { for (var i = 0; i < RippleAnimationManager.GetAnimationCount(); i++) { Int32 rippleSize = (RippleAnimationManager.GetDirection(i) == AnimationDirection.InOutIn) ? (int)(21 * (0.8d + (0.2d * RippleAnimationManager.GetProgress(i)))) : 21; if (CheckAlign == ContentAlignment.MiddleLeft) { X = 12 - rippleSize / 2 - 2; } else if (CheckAlign == ContentAlignment.MiddleRight) { X = (Width - (12 - rippleSize / 2 - 2) - rippleSize) - 2; } else if (CheckAlign == ContentAlignment.MiddleCenter) { X = (Width / 2 - (rippleSize / 2)) - 1; } else { X = 12 - rippleSize / 2 - 2; } using (GraphicsPath Path = DrawHelper.CreateRoundRect(X, ((Height / 2 - 6) + (18 / 2) - 1) - rippleSize / 2 - 3, rippleSize + 1, rippleSize + 1, rippleSize / 2)) { e.Graphics.FillPath(new SolidBrush(Color.FromArgb((int)((RippleAnimationManager.GetProgress(i) * 40)), FlatAppearance.MouseDownBackColor)), Path); } } } // Отрисовка поля "Checked" if (CheckAlign == ContentAlignment.MiddleLeft) { X = 5; } else if (CheckAlign == ContentAlignment.MiddleRight) { X = Width - 6 - 12; } else if (CheckAlign == ContentAlignment.MiddleCenter) { X = (Width / 2 - 6); } else { X = 5; } using (GraphicsPath checkmarkPath = DrawHelper.CreateRoundRect(X, (Height / 2 - 6), 12, 12, 1f)) { if (Enabled) { e.Graphics.FillPath(new SolidBrush(Parent.BackColor), checkmarkPath); e.Graphics.DrawPath(new Pen(FlatAppearance.BorderColor), checkmarkPath); } else if (Checked) { e.Graphics.SmoothingMode = SmoothingMode.None; e.Graphics.FillRectangle(new SolidBrush(FlatAppearance.BorderColor), (Height / 2 - 6) + 2, (Height / 2 - 6) + 2, 14, 14); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; } Bitmap Tick = new Bitmap(15, 13); using (Graphics GIMG = Graphics.FromImage(Tick)) { PointF[] Lines = { new PointF(2, 7), new PointF(3, 5), new PointF(5, 8), new PointF(13, -1), new PointF(15, 1), new PointF(5, 11), new PointF(2, 7) }; GIMG.FillRectangle(new SolidBrush(BackColor), new Rectangle(11, 0, 2, 6)); GIMG.FillPolygon(new SolidBrush(_checkedColor), Lines); } e.Graphics.DrawImageUnscaledAndClipped(Tick, new Rectangle(X, (Height / 2) - 6, (int)(15.0 * AnimationManager.GetProgress()), 13)); } // Отрисовка текста e.Graphics.DrawString( Text, Font, new SolidBrush(ForeColor), new PointF(22, Height / 2 - e.Graphics.MeasureString(Text, Font).Height / 2)); }
protected override void OnPaint(PaintEventArgs pevent) { var g = pevent.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHint.AntiAlias; // clear the control g.Clear(Parent.BackColor); var CHECKBOX_CENTER = _boxOffset + CHECKBOX_SIZE_HALF - 1; var animationProgress = _animationManager.GetProgress(); var colorAlpha = Enabled ? (int)(animationProgress * 255.0) : SkinManager.GetCheckBoxOffDisabledColor().A; var backgroundAlpha = Enabled ? (int)(SkinManager.GetCheckboxOffColor().A *(1.0 - animationProgress)) : SkinManager.GetCheckBoxOffDisabledColor().A; var brush = new SolidBrush(Color.FromArgb(colorAlpha, Enabled ? SkinManager.ColorScheme.AccentColor : SkinManager.GetCheckBoxOffDisabledColor())); var brush3 = new SolidBrush(Enabled ? SkinManager.ColorScheme.AccentColor : SkinManager.GetCheckBoxOffDisabledColor()); var pen = new Pen(brush.Color); // draw ripple animation if (Ripple && _rippleAnimationManager.IsAnimating()) { for (var i = 0; i < _rippleAnimationManager.GetAnimationCount(); i++) { var animationValue = _rippleAnimationManager.GetProgress(i); var animationSource = new Point(CHECKBOX_CENTER, CHECKBOX_CENTER); var rippleBrush = new SolidBrush(Color.FromArgb((int)((animationValue * 40)), ((bool)_rippleAnimationManager.GetData(i)[0]) ? Color.Black : brush.Color)); var rippleHeight = (Height % 2 == 0) ? Height - 3 : Height - 2; var rippleSize = (_rippleAnimationManager.GetDirection(i) == AnimationDirection.InOutIn) ? (int)(rippleHeight * (0.8d + (0.2d * animationValue))) : rippleHeight; using (var path = DrawHelper.CreateRoundRect(animationSource.X - rippleSize / 2, animationSource.Y - rippleSize / 2, rippleSize, rippleSize, rippleSize / 2)) { g.FillPath(rippleBrush, path); } rippleBrush.Dispose(); } } brush3.Dispose(); var checkMarkLineFill = new Rectangle(_boxOffset, _boxOffset, (int)(17.0 * animationProgress), 17); using (var checkmarkPath = DrawHelper.CreateRoundRect(_boxOffset, _boxOffset, 17, 17, 1f)) { var brush2 = new SolidBrush(DrawHelper.BlendColor(Parent.BackColor, Enabled ? SkinManager.GetCheckboxOffColor() : SkinManager.GetCheckBoxOffDisabledColor(), backgroundAlpha)); var pen2 = new Pen(brush2.Color); g.FillPath(brush2, checkmarkPath); g.DrawPath(pen2, checkmarkPath); g.FillRectangle(new SolidBrush(Parent.BackColor), _boxOffset + 2, _boxOffset + 2, CHECKBOX_INNER_BOX_SIZE - 1, CHECKBOX_INNER_BOX_SIZE - 1); g.DrawRectangle(new Pen(Parent.BackColor), _boxOffset + 2, _boxOffset + 2, CHECKBOX_INNER_BOX_SIZE - 1, CHECKBOX_INNER_BOX_SIZE - 1); brush2.Dispose(); pen2.Dispose(); if (Enabled) { g.FillPath(brush, checkmarkPath); g.DrawPath(pen, checkmarkPath); } else if (Checked) { g.SmoothingMode = SmoothingMode.None; g.FillRectangle(brush, _boxOffset + 2, _boxOffset + 2, CHECKBOX_INNER_BOX_SIZE, CHECKBOX_INNER_BOX_SIZE); g.SmoothingMode = SmoothingMode.AntiAlias; } g.DrawImageUnscaledAndClipped(DrawCheckMarkBitmap(), checkMarkLineFill); } // draw checkbox text SizeF stringSize = g.MeasureString(Text, SkinManager.ROBOTO_MEDIUM_10); g.DrawString( Text, SkinManager.ROBOTO_MEDIUM_10, Enabled ? SkinManager.GetPrimaryTextBrush() : SkinManager.GetDisabledOrHintBrush(), _boxOffset + TEXT_OFFSET, Height / 2 - stringSize.Height / 2); // dispose used paint objects pen.Dispose(); brush.Dispose(); }
protected override void OnPaint(PaintEventArgs pevent) { var g = pevent.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHint.AntiAlias; // clear the control g.Clear(Parent.BackColor); var RADIOBUTTON_CENTER = _boxOffset + RADIOBUTTON_SIZE_HALF; var animationProgress = _animationManager.GetProgress(); int colorAlpha = Enabled ? (int)(animationProgress * 255.0) : SkinManager.GetCheckBoxOffDisabledColor().A; int backgroundAlpha = Enabled ? (int)(SkinManager.GetCheckboxOffColor().A *(1.0 - animationProgress)) : SkinManager.GetCheckBoxOffDisabledColor().A; float animationSize = (float)(animationProgress * 8f); float animationSizeHalf = animationSize / 2; animationSize = (float)(animationProgress * 9f); var brush = new SolidBrush(Color.FromArgb(colorAlpha, Enabled ? SkinManager.ColorScheme.AccentColor : SkinManager.GetCheckBoxOffDisabledColor())); var pen = new Pen(brush.Color); // draw ripple animation if (Ripple && _rippleAnimationManager.IsAnimating()) { for (var i = 0; i < _rippleAnimationManager.GetAnimationCount(); i++) { var animationValue = _rippleAnimationManager.GetProgress(i); var animationSource = new Point(RADIOBUTTON_CENTER, RADIOBUTTON_CENTER); var rippleBrush = new SolidBrush(Color.FromArgb((int)((animationValue * 40)), ((bool)_rippleAnimationManager.GetData(i)[0]) ? Color.Black : brush.Color)); var rippleHeight = (Height % 2 == 0) ? Height - 3 : Height - 2; var rippleSize = (_rippleAnimationManager.GetDirection(i) == AnimationDirection.InOutIn) ? (int)(rippleHeight * (0.8d + (0.2d * animationValue))) : rippleHeight; using (var path = DrawHelper.CreateRoundRect(animationSource.X - rippleSize / 2, animationSource.Y - rippleSize / 2, rippleSize, rippleSize, rippleSize / 2)) { g.FillPath(rippleBrush, path); } rippleBrush.Dispose(); } } // draw radiobutton circle Color uncheckedColor = DrawHelper.BlendColor(Parent.BackColor, Enabled ? SkinManager.GetCheckboxOffColor() : SkinManager.GetCheckBoxOffDisabledColor(), backgroundAlpha); using (var path = DrawHelper.CreateRoundRect(_boxOffset, _boxOffset, RADIOBUTTON_SIZE, RADIOBUTTON_SIZE, 9f)) { g.FillPath(new SolidBrush(uncheckedColor), path); if (Enabled) { g.FillPath(brush, path); } } g.FillEllipse( new SolidBrush(Parent.BackColor), RADIOBUTTON_OUTER_CIRCLE_WIDTH + _boxOffset, RADIOBUTTON_OUTER_CIRCLE_WIDTH + _boxOffset, RADIOBUTTON_INNER_CIRCLE_SIZE, RADIOBUTTON_INNER_CIRCLE_SIZE); if (Checked) { using (var path = DrawHelper.CreateRoundRect(RADIOBUTTON_CENTER - animationSizeHalf, RADIOBUTTON_CENTER - animationSizeHalf, animationSize, animationSize, 4f)) { g.FillPath(brush, path); } } SizeF stringSize = g.MeasureString(Text, SkinManager.ROBOTO_MEDIUM_10); g.DrawString(Text, SkinManager.ROBOTO_MEDIUM_10, Enabled ? SkinManager.GetPrimaryTextBrush() : SkinManager.GetDisabledOrHintBrush(), _boxOffset + 22, Height / 2 - stringSize.Height / 2); brush.Dispose(); pen.Dispose(); }