Public Class UserControl1
Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyBase.BackColor = Color.Red
MyBase.Region = New Region(roundedRectangle(0, 0, MyBase.Width - 10, MyBase.Height - 10, 10))
End Sub
Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.FillPath(Brushes.White, roundedRectangle(1, 1, MyBase.Width - 12, MyBase.Height - 12, 10))
End Sub
Public Function roundedRectangle(ByVal X As Integer, ByVal Y As Integer, _
ByVal Width As Integer, ByVal Height As Integer, ByVal diameter As Integer) As System.Drawing.Drawing2D.GraphicsPath
''the 'diameter' parameter changes the size of the rounded region
Dim graphics_path As New System.Drawing.Drawing2D.GraphicsPath
Dim BaseRect As New RectangleF(X, Y, Width, Height)
Dim ArcRect As New RectangleF(BaseRect.Location, New SizeF(diameter, diameter))
'top left Arc
graphics_path.AddArc(ArcRect, 180, 90)
graphics_path.AddLine(X + CInt(diameter / 2), _
Y, X + Width - CInt(diameter / 2), Y)
' top right arc
ArcRect.X = BaseRect.Right - diameter
graphics_path.AddArc(ArcRect, 270, 90)
graphics_path.AddLine(X + Width, _
Y + CInt(diameter / 2), X + Width, _
Y + Height - CInt(diameter / 2))
' bottom right arc
ArcRect.Y = BaseRect.Bottom - diameter
graphics_path.AddArc(ArcRect, 0, 90)
graphics_path.AddLine(X + CInt(diameter / 2), _
Y + Height, X + Width - CInt(diameter / 2), _
Y + Height)
' bottom left arc
ArcRect.X = BaseRect.Left
graphics_path.AddArc(ArcRect, 90, 90)
graphics_path.AddLine(X, Y + CInt(diameter / 2), _
X, Y + Height - CInt(diameter / 2))
Return graphics_path
End Function
End Class