Round buttons

How to make a button in a round shape, not in a regular rectangle.

I am using winforms (2.0)

+5
source share
5 answers

There are many articles about these things in the Code project, especially the RoundButton Windows Control article - Ever Decreasing Circles may be of interest because it shows you have to make different round buttons.

+5
source

First create a class. Give it the name Round Button. Then write the code directly as follows:

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 create the application and close it. Now go to the toolbar and you will see a control named RoundButton. Then dope and drop it on the shape of your window and test it ...... Enjoy!

+27
source

I need to implement my own Button class based on the default Windows Forms button. Something like this or this . You can use Google to find more examples.

+2
source
  GraphicsPath p = new GraphicsPath(); p.AddEllipse(1, 1, button1.Width - 4, button1.Height - 4); button1.Region = new Region(p); 
0
source

This is what you want.

 public class RoundButton : Control { private readonly Label lbl; public RoundButton() : base() { lbl = new Label { Text = Text, ForeColor = ForeColor, BackColor = BackColor, Font = Font }; CenterInParent(); } private void CenterInParent() { lbl.Left = (Width - lbl.Width) / 2; lbl.Top = (Height - lbl.Height) / 2; } protected override void OnPaint(PaintEventArgs e) { GraphicsPath grPath = new GraphicsPath(); grPath.AddEllipse(0, 0, ClientSize.Width, ClientSize.Height); Region = new Region(grPath); base.OnPaint(e); } protected override void OnMove(EventArgs e) { CenterInParent(); base.OnMove(e); } protected override void OnTextChanged(EventArgs e) { lbl.Text = Text; base.OnTextChanged(e); } protected override void OnForeColorChanged(EventArgs e) { lbl.ForeColor = ForeColor; base.OnForeColorChanged(e); } protected override void OnBackColorChanged(EventArgs e) { lbl.BackColor = BackColor; base.OnBackColorChanged(e); } protected override void OnFontChanged(EventArgs e) { lbl.Font = Font; base.OnFontChanged(e); } } 

Pros:

  • No cuts

  • Round

Minuses:

  • Wrong design loader for round button
0
source

All Articles