How to Create a Round Button in VB.Net

In this tutorial, I will teach you how to create a round button in vb.net. This method has the ability to remove the sharpen the edge of a button that makes it round depends on the value that you put. This is a simple method, then it is easy to follow.

Creating an Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application for visual basic. figure 1

Step 2

Do the form just like shown below. figure 2

Step 3

Press F7 to open the code editor. After that, create a method for creating a round button.
  1.  
  2. Private Sub RoundButton(btn As Button)
  3.  
  4. btn.FlatStyle = FlatStyle.Flat
  5. btn.FlatAppearance.BorderSize = 0
  6. btn.BackColor = Color.Red
  7. btn.ForeColor = Color.White
  8. btn.Cursor = Cursors.Hand
  9. btn.Font = New Font("Century Gothic", 14)
  10.  
  11. Dim Raduis As New Drawing2D.GraphicsPath
  12.  
  13. Raduis.StartFigure()
  14. 'appends an elliptical arc to the current figure
  15. 'left corner top
  16. Raduis.AddArc(New Rectangle(0, 0, 20, 20), 180, 90)
  17. 'appends a line segment to the current figure
  18. Raduis.AddLine(10, 0, btn.Width - 20, 0)
  19. 'appends an elliptical arc to the current figure
  20. 'right corner top
  21. Raduis.AddArc(New Rectangle(btn.Width - 20, 0, 20, 20), -90, 90)
  22. 'appends a line segment to the current figure
  23. Raduis.AddLine(btnRound.Width, 20, btn.Width, btn.Height - 10)
  24. 'appends an elliptical arc to the current figure
  25. 'right corner buttom
  26. Raduis.AddArc(New Rectangle(btn.Width - 25, btn.Height - 25, 25, 25), 0, 90)
  27. 'appends a line segment to the current figure
  28. 'left corner bottom
  29. Raduis.AddLine(btn.Width - 10, btn.Width, 20, btn.Height)
  30. 'appends an elliptical arc to the current figure
  31. Raduis.AddArc(New Rectangle(0, btn.Height - 20, 20, 20), 90, 90)
  32. 'Close the current figure and start a new one.
  33. Raduis.CloseFigure()
  34. 'set the window associated with the control
  35. btnRound.Region = New Region(Raduis)
  36. End Sub
Write the following codes to execute the method in the first load of the form.

Step 4

  1.  
  2. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  3. RoundButton(btnRound)
  4. End Sub

Output :

output The complete source code is included. You can download it and run it on your computer. For any questions about this article. You can contact me @ Email – [email protected] Mobile No. – 09305235027 – TNT Or feel free to comment below.

Comments

Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim butarray() As Button = Nothing Dim list As New List(Of Button) For Each button As Button In Me.Controls list.Add(button) Next RoundButton(list.ToArray) End Sub Private Sub RoundButton(btn() As Button) For Each bt In btn bt.FlatStyle = FlatStyle.Flat bt.FlatAppearance.BorderSize = 0 bt.BackColor = Color.Red bt.ForeColor = Color.White bt.Cursor = Cursors.Hand bt.Font = New Font("Century Gothic", 14) Dim Raduis As New Drawing2D.GraphicsPath Raduis.StartFigure() 'appends an elliptical arc to the current figure 'left corner top Raduis.AddArc(New Rectangle(0, 0, 20, 20), 180, 90) 'appends a line segment to the current figure Raduis.AddLine(10, 0, bt.Width - 20, 0) 'appends an elliptical arc to the current figure 'right corner top Raduis.AddArc(New Rectangle(bt.Width - 20, 0, 20, 20), -90, 90) 'appends a line segment to the current figure Raduis.AddLine(bt.Width, 20, bt.Width, bt.Height - 10) 'appends an elliptical arc to the current figure 'right corner buttom Raduis.AddArc(New Rectangle(bt.Width - 25, bt.Height - 25, 25, 25), 0, 90) 'appends a line segment to the current figure 'left corner bottom Raduis.AddLine(bt.Width - 10, bt.Width, 20, bt.Height) 'appends an elliptical arc to the current figure Raduis.AddArc(New Rectangle(0, bt.Height - 20, 20, 20), 90, 90) 'Close the current figure and start a new one. Raduis.CloseFigure() 'set the window associated with the control bt.Region = New Region(Raduis) Next End Sub End Class
Submitted bymarc cruz (not verified)on Mon, 07/19/2021 - 08:29

try putting it to other class and inherit it Public Class roundedbutton Inherits Button Private Sub RoundButton(ByVal btn As Button) btn.FlatStyle = FlatStyle.Flat btn.FlatAppearance.BorderSize = 0 btn.BackColor = Color.Red btn.ForeColor = Color.White btn.Cursor = Cursors.Hand btn.Font = New Font("Century Gothic", 14) Dim Raduis As New Drawing2D.GraphicsPath Raduis.StartFigure() 'appends an elliptical arc to the current figure 'left corner top Raduis.AddArc(New Rectangle(0, 0, 20, 20), 180, 120) 'appends a line segment to the current figure Raduis.AddLine(10, 0, btn.Width - 20, 0) 'appends an elliptical arc to the current figure 'right corner top Raduis.AddArc(New Rectangle(btn.Width - 20, 0, 20, 20), -90, 120) 'appends a line segment to the current figure Raduis.AddLine(btn.Width, 20, btn.Width, btn.Height - 10) 'appends an elliptical arc to the current figure 'right corner buttom Raduis.AddArc(New Rectangle(btn.Width - 25, btn.Height - 25, 25, 25), 0, 120) 'appends a line segment to the current figure 'left corner bottom Raduis.AddLine(btn.Width - 10, btn.Width, 20, btn.Height) 'appends an elliptical arc to the current figure Raduis.AddArc(New Rectangle(0, btn.Height - 20, 20, 20), 90, 120) 'Close the current figure and start a new one. Raduis.CloseFigure() 'set the window associated with the control Me.Region = New Region(Raduis) End Sub Public Sub New() MyBase.New() RoundButton(Me) End Sub Private Sub roundedbutton_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged RoundButton(Me) End Sub End Class

Add new comment