Some times we want to draw rounded rectangles or show a form or controls with rounded corners. This class gives you that functionality. The class has two functions "RoundedRectangle" and "RoundedRegion". The "RoundedRectangle" rounds the corners of the rectangle and returns the graphics path. The "RoundedRegion" creates a rectangle-region, rounds the corners and returns the newly created region.
Class Shared Methods:
- RoundedRectangle – Returns the graphics path of the rounded-rectangle (parameters: rectangle, radius and four optional parameters for each corner).
- RoundedRegion – Returns a newly created region with rounded corners (parameters: region size, radius and four optional parameters for each corner).
Usage:
VB Code:
'Draw a rounded rectangle in the form's paint event.
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawPath(Pens.Red, Shape.RoundedRectangle(New Rectangle(5, 5, 100, 100), 8, Shape.Corner.None))
End Sub
'Show the control on the form with rounded corners.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Panel1.Region = Shape.RoundedRegion(Panel1.Size, 10, Shape.Corner.None)
End Sub
Please feel free to comment or notify me about any problems associated with the class.
Download the latest version here