protected override void OnPaint(PaintEventArgs pevent) { var g = pevent.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHint.AntiAlias; g.Clear(Parent.BackColor); using (var backgroundPath = DrawHelper.CreateRoundRect(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1, 1f)) { g.FillPath(Primary ? SkinManager.ColorScheme.PrimaryBrush : SkinManager.GetRaisedButtonBackgroundBrush(), backgroundPath); } if (_animationManager.IsAnimating()) { for (int i = 0; i < _animationManager.GetAnimationCount(); i++) { var animationValue = _animationManager.GetProgress(i); var animationSource = _animationManager.GetSource(i); var rippleBrush = new SolidBrush(Color.FromArgb((int)(51 - (animationValue * 50)), Color.White)); var rippleSize = (int)(animationValue * Width * 2); g.FillEllipse(rippleBrush, new Rectangle(animationSource.X - rippleSize / 2, animationSource.Y - rippleSize / 2, rippleSize, rippleSize)); } } //Icon var iconRect = new Rectangle(8, 6, 24, 24); if (string.IsNullOrEmpty(Text)) { // Center Icon iconRect.X += 2; } if (Icon != null) { g.DrawImage(Icon, iconRect); } //Text var textRect = ClientRectangle; if (Icon != null) { // // Resize and move Text container // // First 8: left padding // 24: icon width // Second 4: space between Icon and Text // Third 8: right padding textRect.Width -= 8 + 24 + 4 + 8; // First 8: left padding // 24: icon width // Second 4: space between Icon and Text textRect.X += 8 + 24 + 4; } g.DrawString( Text.ToUpper(), SkinManager.ROBOTO_MEDIUM_10, SkinManager.GetRaisedButtonTextBrush(Primary), textRect, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }); }
protected override void OnPaint(PaintEventArgs pevent) { var g = pevent.Graphics; g.TextRenderingHint = TextRenderingHint.AntiAlias; g.Clear(Parent.BackColor); //Hover Color c = SkinManager.GetFlatButtonHoverBackgroundColor(); using (Brush b = new SolidBrush(Color.FromArgb((int)(_hoverAnimationManager.GetProgress() * c.A), c.RemoveAlpha()))) g.FillRectangle(b, ClientRectangle); //Ripple if (_animationManager.IsAnimating()) { g.SmoothingMode = SmoothingMode.AntiAlias; for (var i = 0; i < _animationManager.GetAnimationCount(); i++) { var animationValue = _animationManager.GetProgress(i); var animationSource = _animationManager.GetSource(i); using (Brush rippleBrush = new SolidBrush(Color.FromArgb((int)(101 - (animationValue * 100)), Color.Black))) { var rippleSize = (int)(animationValue * Width * 2); g.FillEllipse(rippleBrush, new Rectangle(animationSource.X - rippleSize / 2, animationSource.Y - rippleSize / 2, rippleSize, rippleSize)); } } g.SmoothingMode = SmoothingMode.None; } //Icon var iconRect = new Rectangle(8, 6, 24, 24); if (string.IsNullOrEmpty(Text)) { // Center Icon iconRect.X += 2; } if (Icon != null) { g.DrawImage(Icon, iconRect); } //Text var textRect = ClientRectangle; if (Icon != null) { // // Resize and move Text container // // First 8: left padding // 24: icon width // Second 4: space between Icon and Text // Third 8: right padding textRect.Width -= 8 + 24 + 4 + 8; // First 8: left padding // 24: icon width // Second 4: space between Icon and Text textRect.X += 8 + 24 + 4; } g.DrawString( Text.ToUpper(), SkinManager.ROBOTO_MEDIUM_10, Enabled ? (Primary ? SkinManager.ColorScheme.PrimaryBrush : SkinManager.GetPrimaryTextBrush()) : SkinManager.GetFlatButtonDisabledTextBrush(), textRect, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center } ); }