65.9K
CodeProject is changing. Read more.
Home

Professional Karub Button

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.52/5 (13 votes)

Jul 31, 2007

1 min read

viewsIcon

27430

downloadIcon

1089

This is a Karub Button, Normal - Highlighted and Pressed States

Screenshot - Image.png

Introduction

This is my Karub Button. It has a few style features. You can create your button style and you must test it. The button has several color properties. They are normal state color, highlighted state color and pressed state color. For instance:

Normal State Style

Screenshot - Image4.png

Highlighted State Style

Screenshot - custom.png

And Pressed State Style

Screenshot - customDown.png

Background

This project language is C# 2005. It includes several properties. For example: button icon, icon style, text style, text dimension, layer style, icon and text alignment and much more. But, you can see some properties on an article. Look at my property window.

Screenshot - Property.png

Icon Style

Highlighted Type

Screenshot - Image4.png

Whitened Type

Screenshot - Image3.png

DarkColor Type

Screenshot - Image2.png

And Much More Style for This Property

One Sample Text Style

Screenshot - Image1.png

You can change text style on this button. Only, you must select your favourite text style at this project.

Another Karub Button Style

Screenshot - fox.png

If you want to change your icon or text location on the button, you must do select of connected with property. You can exchange a lot of special features at this button control.

Using the Code

protected virtual void DrawButton(Graphics g)
{
    Rectangle backRect = new Rectangle();
    Rectangle ShineRect = new Rectangle();
    if (_sinir == BorderLine.Up)//tamam
    {
        backRect = new Rectangle(1, this.Height / 2 - 1, this.Width - 2, this.Height / 2);
        ShineRect = new Rectangle(1, 1, this.Width - 2, this.Height / 2 - 2);//üstteki
    }
    else if (_sinir == BorderLine.Center)//tamam
    {
        backRect = new Rectangle(1, this.Height / 2, this.Width - 2, this.Height / 2 - 1);
        ShineRect = new Rectangle(1, 1, this.Width - 2, this.Height / 2 - 1);//üstteki
    }
    else if (_sinir == BorderLine.Down)//tamam
    {
        backRect = new Rectangle(1, this.Height / 2 + 1, this.Width - 2, this.Height / 2 - 2);
        ShineRect = new Rectangle(1, 1, this.Width - 2, this.Height / 2);//üstteki
    }
    LinearGradientBrush lgb;//dispose edilecek
    int k = (int)butonDurum;//butonun durumunu tutacak
    if (_buttonStyle == Style.CalmCyan)
    {
        lgb = new LinearGradientBrush(backRect, renkDizi[0][k, 1], 
              renkDizi[0][k, 0], LinearGradientMode.Vertical);
        g.FillRectangle(lgb, backRect);
        lgb = new LinearGradientBrush(ShineRect, renkDizi[0][k, 2], 
              renkDizi[0][k, 3], LinearGradientMode.Vertical);
        g.FillRectangle(lgb, ShineRect);
        //Top-Bottom Border draw
        g.DrawLine(new Pen(renkDizi[0][k, 6]), 1, 1, this.Width - 2, 1);
        g.DrawLine(new Pen(renkDizi[0][k, 7]), 1, this.Height - 2, 
                   this.Width - 2, this.Height - 2);
        //Left-Right Border draw
        g.DrawLine(new Pen(renkDizi[0][k, 4]), 1, 1, 1, this.Height - 2);
        g.DrawLine(new Pen(renkDizi[0][k, 5]), this.Width - 2, 1, 
                   this.Width - 2, this.Height - 3);
        if (uzeri)
            g.DrawRectangle(new Pen(renkCenter[0]), 0, 0, this.Width - 1, this.Height - 1);
    }
    else if (_buttonStyle == Style.DiamondRed)
    {
        lgb = new LinearGradientBrush(backRect, renkDizi[1][k, 1], 
              renkDizi[1][k, 0], LinearGradientMode.Vertical);
        g.FillRectangle(lgb, backRect);
        lgb = new LinearGradientBrush(ShineRect, renkDizi[1][k, 2], 
              renkDizi[1][k, 3], LinearGradientMode.Vertical);
        g.FillRectangle(lgb, ShineRect);
        g.DrawLine(new Pen(renkDizi[1][k, 6]), 1, 1, this.Width - 2, 1);
        g.DrawLine(new Pen(renkDizi[1][k, 7]), 1, this.Height - 2, 
                   this.Width - 2, this.Height - 2);
        g.DrawLine(new Pen(renkDizi[1][k, 4]), 1, 1, 1, this.Height - 2);
        g.DrawLine(new Pen(renkDizi[1][k, 5]), this.Width - 2, 1, 
                   this.Width - 2, this.Height - 3);
        if (uzeri)
            g.DrawRectangle(new Pen(renkCenter[1]), 0, 0, this.Width - 1, this.Height - 1);
    }
    else
    {
        lgb = new LinearGradientBrush(backRect, renkDizi[2][k, 1], 
              renkDizi[2][k, 0], LinearGradientMode.Vertical);
        g.FillRectangle(lgb, backRect);
        lgb = new LinearGradientBrush(ShineRect, renkDizi[2][k, 2], 
              renkDizi[2][k, 3], LinearGradientMode.Vertical);
        g.FillRectangle(lgb, ShineRect);
        g.DrawLine(new Pen(renkDizi[2][k, 6]), 1, 1, this.Width - 2, 1);
        g.DrawLine(new Pen(renkDizi[2][k, 7]), 1, this.Height - 2, 
                   this.Width - 2, this.Height - 2);
        g.DrawLine(new Pen(renkDizi[2][k, 4]), 1, 1, 1, this.Height - 2);
        g.DrawLine(new Pen(renkDizi[2][k, 5]), this.Width - 2, 1, 
                   this.Width - 2, this.Height - 3);
        if (uzeri)
            g.DrawRectangle(new Pen(renkCenter[2]), 0, 0, this.Width - 1, this.Height - 1);
    }
    if (_Layer != LayerStatus.None)
    {
        int x = 0, y = 0;
        switch (_Layer)
        {
             case LayerStatus.Bottom:
                y += Size.Height / 2 - 1;
                break;
            case LayerStatus.BottomLeft:
                x -= Size.Width / 2;
                y += Size.Height / 2 - 1;
                break;
            case LayerStatus.BottomRight:
                x += Size.Width / 2;
                y += Size.Height / 2 - 1;
                break;
            case LayerStatus.Left:
                x -= Size.Width / 2;
                break;
            case LayerStatus.Right:
                x += Size.Width / 2;
                break;
            case LayerStatus.Top:
                y -= Size.Height / 2 + 1;
                break;
            case LayerStatus.TopLeft:
                x -= Size.Width / 2;
                y -= Size.Height / 2 + 1;
                break;
            case LayerStatus.TopRight:
                x += Size.Width / 2;
                y -= Size.Height / 2 + 1;
                break;
        }
    Point startPoint = new Point(x - _GlowLength, y - _GlowLength);
    GraphicsPath pth = new GraphicsPath();
    pth.AddRectangle(new Rectangle
      (startPoint, new Size(Size.Width + _GlowLength * 2, Size.Height + _GlowLength * 2)));
    PathGradientBrush pgb = new PathGradientBrush(pth);
    pgb.CenterColor = _layerCenterColor;
    pgb.SurroundColors = new Color[] { Color.Transparent };
    pgb.FocusScales = new PointF(0.7F, 0.7F);
    ColorBlend cb = new ColorBlend(2);
    cb.Positions[0] = 0.0F;
    cb.Positions[1] = 1.0F;
    cb.Colors = new Color[] { Color.Transparent, Color.FromArgb(150, 93, 198, 242) };
    pgb.InterpolationColors = cb;
    pgb.FocusScales = new PointF(0.7F, 0.7F);
    g.FillPath(pgb, pth);//alanı dolduruyoruz.
    lgb.Dispose();
    pgb.Dispose();
    pth.Dispose();
    }
}

History

  • 31st July, 2007: Initial version

License

This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below. A list of licenses authors might use can be found here.