Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round shaped buttons

Tags:

c#

winforms

How do I make a button in a round shape rather than the conventional rectangle.

I am using winforms(2.0)

like image 585
karthik Avatar asked Sep 14 '10 10:09

karthik


3 Answers

First make a class. Give it name: "RoundButton". Then write the code directly as this:

using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{
    public class RoundButton : Button
    {
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            GraphicsPath grPath = new GraphicsPath();
            grPath.AddEllipse(0, 0, ClientSize.Width, ClientSize.Height);
            this.Region = new System.Drawing.Region(grPath);
            base.OnPaint(e);
        }
    }

}

Then, build your application and close this.

Now go to the toolbox and you will see a control named RoundButton.

Then drag and drop this on your Windows form and test it.

like image 56
Salman Srabon Avatar answered Sep 29 '22 17:09

Salman Srabon


GraphicsPath p = new GraphicsPath();
p.AddEllipse(1, 1, button1.Width - 4, button1.Height - 4);
button1.Region = new Region(p);
like image 35
Jig12 Avatar answered Sep 29 '22 17:09

Jig12


Code project has many articles about these kinds of things, especially the article RoundButton Windows Control - Ever Decreasing Circles might be of interest since it shows you have to do different kinds of round buttons.

like image 40
Hans Olsson Avatar answered Sep 29 '22 17:09

Hans Olsson