private string GetClassName()
        {
            var builder = new System.Text.StringBuilder();

            builder.Append("btn");
            if (BtnStyle != VBtnStyle.Default)
            {
                builder.Append($" btn-{BtnStyle.ToString().ToLower()}");
            }
            if (BtnSize != VBtnSize.Default)
            {
                builder.Append($" btn-{BtnSize.ToString().ToLower()}");
            }
            return(builder.ToString());
        }
Beispiel #2
0
 public BtnStateInfo(Rectangle rect, BtnState state, BtnStyle style,
                     int cornerRadius, Color borderColor, Color innerBorderColor, Color backColor, ColorBlend blend,
                     string text, Font font, StringFormat textFormat, Color foreColor, Rectangle textRect,
                     Image image, ContentAlignment imageAlign, GraphicsPath imgPath, Rectangle imgRect)
 {
     Rect             = rect;
     State            = state;
     Style            = style;
     CornerRadius     = cornerRadius;
     BorderColor      = borderColor;
     InnerBorderColor = innerBorderColor;
     BackColor        = backColor;
     Blend            = blend;
     Text             = text.Length > 20 ? text.Substring(0, 17) + "..." : text;
     Font             = font;
     TextFormat       = textFormat;
     ForeColor        = foreColor;
     TextRect         = textRect;
     Image            = image;
     ImageAlign       = imageAlign;
     ImgPath          = imgPath;
     ImgRect          = imgRect;
 }
Beispiel #3
0
        private static void DrawBackground(Graphics g, Rectangle rect, BtnStyle style, BtnState state,
                                           int cornerRadius, Color borderColor, Color innerBorderColor, Color backColor, ColorBlend blend)
        {
            Rectangle rr = new Rectangle(rect.X, rect.Y, rect.Width - 1, rect.Height - 1);

            if (style == BtnStyle.Flat)
            {
                using (GraphicsPath path = GetRoundedRect(rr, cornerRadius))
                {
                    using (SolidBrush brush = new SolidBrush(backColor))
                    {
                        g.FillPath(brush, path);
                    }

                    using (Pen p = new Pen(borderColor, 1))
                    {
                        g.DrawPath(p, path);
                    }
                }
            }
            else if (style == BtnStyle.Fixed3D)
            {
                using (SolidBrush brush = new SolidBrush(backColor))
                {
                    g.FillRectangle(brush, rr);
                }

                using (Pen blackpen = new Pen(Color.Black, 2))
                    using (Pen whitepen = new Pen(Color.White, 2))
                    {
                        g.DrawLine(state == BtnState.Pushed ? blackpen : whitepen, rr.Left, rr.Top, rr.Right - 1, rr.Top);
                        g.DrawLine(state == BtnState.Pushed ? blackpen : whitepen, rr.Left, rr.Top, rr.Left, rr.Bottom - 1);
                        g.DrawLine(state == BtnState.Pushed ? whitepen : blackpen, rr.Right, rr.Top, rr.Right, rr.Bottom);
                        g.DrawLine(state == BtnState.Pushed ? whitepen : blackpen, rr.Left, rr.Bottom, rr.Right - 1, rr.Bottom);
                    }
            }
            else
            {
                using (GraphicsPath path = GetRoundedRect(rr, cornerRadius))
                {
                    using (LinearGradientBrush brush = new LinearGradientBrush(rr, backColor, backColor, LinearGradientMode.Vertical))
                    {
                        brush.InterpolationColors = blend;
                        g.FillPath(brush, path);
                    }

                    rr = new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3);

                    if (innerBorderColor != Color.Transparent)
                    {
                        using (GraphicsPath innerPath = GetRoundedRect(rr, cornerRadius))
                            using (Pen p = new Pen(innerBorderColor, 2))
                            {
                                g.DrawPath(p, innerPath);
                            }
                    }

                    using (Pen p = new Pen(borderColor, 1))
                    {
                        g.DrawPath(p, path);
                    }
                }
            }
        }