0

I have a requirement to create a round corner buttons but I am new to dev express.Do we have any buttons in Dev express 8.2 which supports round corner.With normal button i tried following code but it didnt work.

  public class RoundButton : Button
{
    protected override void OnResize(EventArgs e)
    {
        using (var path = new System.Drawing.Drawing2D.GraphicsPath())
        {
            path.AddEllipse(new Rectangle(0, 0, 80, 30));
            this.Region = new Region(path);
        }
        base.OnResize(e);
    }
}
Rakesh Devarasetti
  • 1,409
  • 2
  • 24
  • 42

1 Answers1

0
  public class RoundButton : Button
{
    bool isMouseEnter = false;
    GraphicsPath GetRoundPath(RectangleF Rect, int radius)
    {
        float r2 = radius / 2f;
        GraphicsPath GraphPath = new GraphicsPath();

        GraphPath.AddArc(Rect.X-1, 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, 271, 90);
        GraphPath.AddLine(Rect.Width, Rect.Y + r2, Rect.Width, Rect.Height - r2);
        GraphPath.AddArc(Rect.X + Rect.Width - radius - 1,
                         Rect.Y + Rect.Height - radius, radius, radius, 1, 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;
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        RectangleF Rect = new RectangleF(0, 0, this.Width, this.Height);
        GraphicsPath GraphPath = GetRoundPath(Rect, 10);
        this.Region = new Region(GraphPath);
        using (Pen pen = new Pen(System.Drawing.Color.FromArgb(74, 174, 74), 8.25F))
        {
            if (isMouseEnter)
                pen.Color = System.Drawing.Color.FromArgb(88, 208, 88);
            pen.Alignment = PenAlignment.Inset;
            e.Graphics.DrawPath(pen, GraphPath);
        }
    }
    protected override void OnMouseEnter(EventArgs e)
    {
        base.OnMouseEnter(e);
        isMouseEnter = true;
    }
    protected override void OnMouseLeave(EventArgs e)
    {
        base.OnMouseLeave(e);
        isMouseEnter = false;
    }
}
Rakesh Devarasetti
  • 1,409
  • 2
  • 24
  • 42