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
Highlighted State Style
And Pressed State Style
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.
Icon Style
Highlighted Type
Whitened Type
DarkColor Type
And Much More Style for This Property
One Sample Text Style
You can change text style on this button. Only, you must select your favourite text style at this project.
Another Karub Button Style
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)
{
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);
}
else if (_sinir == BorderLine.Center)
{
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);
}
else if (_sinir == BorderLine.Down)
{
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);
}
LinearGradientBrush lgb;
int k = (int)butonDurum;
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);
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);
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);
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.
Since 1998...
MCPD - Enterprise Application Developer
“Hesaplı hareket ettiğini zanneden ve onunla iftihar eyliyen dar kafalar; kurtulmağa, yükselmeğe elverişli hiç bir eser vücüda getirmezler. Kurtuluş ve yükselişi, ancak varlığına dayanan ve mülkü milletin gizli kapalı hazinelerini verimli hale getirmesini bilen, şahsi menfaatini millet menfaati uğruna feda eden, ruhu idealist, dimağı realist şahsiyetlerde aramalıdır.”
Nuri Demirağ, 1947