C# Create A Rounded Button

Publicado el: 13 febrero 2019
en el canal de: CSharp61Programmer
488
7

C# From Beginner To Pro - Create A Rounded Button. Here is the code so you will not have to type.

public class RoundButton : Button
{

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);

RectangleF Rect = new RectangleF(0, 0, this.Width, this.Height);
GraphicsPath GraphPath = GetRoundPath(Rect, 48);

this.Region = new Region(GraphPath);
Color borderColor = this.FlatAppearance.BorderColor;

using (Pen pen = new Pen(borderColor, 1.65f))
{
pen.Alignment = PenAlignment.Inset;

e.Graphics.InterpolationMode = InterpolationMode.High;
e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

e.Graphics.DrawPath(pen, GraphPath);
}
}


GraphicsPath GetRoundPath(RectangleF Rect, int radius)
{
float r2 = radius / 2f;
GraphicsPath GraphPath = new GraphicsPath();

GraphPath.AddArc(Rect.X, Rect.Y, radius, radius, 180, 90);
GraphPath.AddLine(Rect.X + r2, Rect.Y, Rect.Width - r2, Rect.Y);
GraphPath.AddArc(Rect.X + Rect.Width - radius, Rect.Y, radius, radius, 270, 90);
GraphPath.AddLine(Rect.Width, Rect.Y + r2, Rect.Width, Rect.Height - r2);
GraphPath.AddArc(Rect.X + Rect.Width - radius,
Rect.Y + Rect.Height - radius, radius, radius, 0, 90);
GraphPath.AddLine(Rect.Width - r2, Rect.Height, Rect.X + r2, Rect.Height);
GraphPath.AddArc(Rect.X, Rect.Y + Rect.Height - radius, radius, radius, 90, 90);
GraphPath.AddLine(Rect.X, Rect.Height - r2, Rect.X, Rect.Y + r2);

GraphPath.CloseFigure();
return GraphPath;
}


}


En esta página del sitio puede ver el video en línea C# Create A Rounded Button de Duración hora minuto segunda en buena calidad , que subió el usuario CSharp61Programmer 13 febrero 2019, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 488 veces y le gustó 7 a los espectadores. Disfruta viendo!