Hi, i have a button.
but the button is not animated.
I want animate it like Guna.UI2 or Bunifu.
The source code is :
[ToolboxBitmap(typeof(Button))]
public class SButton : Button
{
int bra = 20;
StringAlignment ha = StringAlignment.Center;
StringAlignment va = StringAlignment.Center;
public StringAlignment HorizontalAlignment
{
get { return ha; }
set { ha = value; Invalidate(); }
}
public StringAlignment VerticalAlignment
{
get { return va; }
set { va = value; Invalidate(); }
}
public int BorderRadius
{
get { return bra; }
set { bra = value; this.Invalidate(); }
}
public SButton() { BackColor = Color.White; ForeColor = Color.Black; Font = new Font("Segoe UI", 13, FontStyle.Bold); }
static int GetFontWidth(int textlength, Font font)
{
return textlength * (int)font.Size;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
e.Graphics.Clear(Parent.BackColor);
if (bra < 2)
{
SolidBrush s = new SolidBrush(BackColor);
e.Graphics.FillRectangle(s, ClientRectangle);
}
else
{
GraphicsPath path = new GraphicsPath();
path.AddArc(new Rectangle(0, 0, bra, bra), 180, 90);
path.AddArc(new Rectangle(Width - bra, 0, bra, bra), -90, 90);
path.AddArc(new Rectangle(Width - bra, Height - bra, bra, bra), 0, 90);
path.AddArc(new Rectangle(0, Height - bra, bra, bra), 90, 90);
e.Graphics.FillPath(new SolidBrush(BackColor), path);
}
e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor),ClientRectangle, new StringFormat() { LineAlignment = ha, Alignment = va } );
if (Image != null)
{
if (ImageAlign == ContentAlignment.TopLeft)
{
e.Graphics.DrawImage(Image, new Point(16, 16));
}else if (ImageAlign == ContentAlignment.TopCenter)
{
e.Graphics.DrawImage(Image, new Point(this.Width / 2 - Image.Width / 2, 16));
}else if (ImageAlign == ContentAlignment.TopRight)
{
e.Graphics.DrawImage(Image, new Point(this.Width - Image.Width - 16, 16));
}else if (ImageAlign == ContentAlignment.MiddleLeft)
{
e.Graphics.DrawImage(Image, new Point(16, this.Height / 2 - Image.Height / 2));
}else if (ImageAlign == ContentAlignment.MiddleCenter)
{
e.Graphics.DrawImage(Image, new Point(this.Width / 2 - Image.Width / 2, this.Height / 2 - Image.Height / 2));
}else if (ImageAlign == ContentAlignment.MiddleRight)
{
e.Graphics.DrawImage(Image, new Point(this.Width - Image.Width - 16, this.Height / 2 - Image.Height / 2));
}else if (ImageAlign == ContentAlignment.BottomLeft)
{
e.Graphics.DrawImage(Image, new Point(16, this.Height - Image.Height - 16));
}
else if (ImageAlign == ContentAlignment.BottomCenter)
{
e.Graphics.DrawImage(Image, new Point(this.Width / 2 - Image.Width / 2, this.Height - Image.Height - 16));
}
else if (ImageAlign == ContentAlignment.BottomRight)
{
e.Graphics.DrawImage(Image, new Point(this.Width - Image.Width - 16, this.Height - Image.Height - 16));
}
}
}
}
What I have tried:
Search the Internet for animated buttons.