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

            Graphics G = e.Graphics;

            G.SmoothingMode = SmoothingMode.HighQuality;

            var BG          = DrawHelper.CreateRoundRect(1, 1, Width - 3, Height - 3, 1);
            var ThumbnailBG = DrawHelper.CreateLeftRoundRect(1, 1, 50, 49, 1);

            G.FillPath(new SolidBrush(MaterialSkinManager.GetApplicationBackgroundColor()), BG);
            //Hover
            Color c = MaterialSkinManager.GetFlatButtonHoverBackgroundColor();

            using (Brush b = new SolidBrush(Color.FromArgb((int)(hoverAnimationManager.GetProgress() * c.A), c.RemoveAlpha())))
                G.FillPath(b, BG);
            G.DrawPath(new Pen(MaterialSkinManager.GetDividersColor()), BG);

            G.FillPath(MaterialSkinManager.ColorScheme.PrimaryBrush, ThumbnailBG);
            G.DrawPath(MaterialSkinManager.ColorScheme.PrimaryPen, ThumbnailBG);

            if (image != null)
            {
                G.DrawImage(image, 3, 3, 48, 47);
            }
            if (Enabled)
            {
                G.DrawString(Text, MaterialSkinManager.ROBOTO_MEDIUM_10, Primary ? MaterialSkinManager.ColorScheme.PrimaryBrush : MaterialSkinManager.GetPrimaryTextBrush(), new PointF(58.6f, 9f));
            }
            else
            {
                G.DrawString(Text, MaterialSkinManager.ROBOTO_MEDIUM_10, new SolidBrush(MaterialSkinManager.GetDisabledOrHintColor()), new PointF(58.6f, 9f));
            }

            G.TextRenderingHint = TextRenderingHint.AntiAlias;
            G.DrawString(info, MaterialSkinManager.ROBOTO_REGULAR_9, new SolidBrush(MaterialSkinManager.GetSecondaryTextColor()), new PointF(59.1f, 26f));
            if (!DesignMode && Controls.Count > 0)
            {
                this.DrawChildShadow(G);
            }
        }
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);
            var g = pevent.Graphics;

            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.TextRenderingHint = TextRenderingHint.AntiAlias;

            using (var backgroundPath = DrawHelper.CreateRoundRect(ClientRectangle.X,
                                                                   ClientRectangle.Y,
                                                                   ClientRectangle.Width - 1,
                                                                   ClientRectangle.Height - 1,
                                                                   _roundedCorner))
            {
                g.FillPath(Primary ? MaterialSkinManager.ColorScheme.PrimaryBrush : MaterialSkinManager.GetRaisedButtonBackgroundBrush(), backgroundPath);
                Color c = MaterialSkinManager.GetFlatButtonHoverBackgroundColor();
                using (Brush b = new SolidBrush(Color.FromArgb((int)(hoverAnimationManager.GetProgress() * c.A), c.RemoveAlpha())))
                    g.FillPath(b, 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
            Rectangle iconRect = new Rectangle(8, 6, 24, 24);

            if (string.IsNullOrEmpty(Text))
            {
                // Center Icon
                iconRect.X += 2;
            }

            if (Icon != null)
            {
                g.DrawImage(Icon, iconRect);
            }

            //Text
            Rectangle 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(),
                Font,
                MaterialSkinManager.GetRaisedButtonTextBrush(Primary),
                textRect,
                new StringFormat {
                Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
            });
            if (!DesignMode && Controls.Count > 0)
            {
                this.DrawChildShadow(g);
            }
        }