Public Structure RoundRectangle
#Region "Fields"
Private rec As Rectangle
Private d, d1, d2, d3, d4 As Integer
#End Region
#Region "Properties"
Public Property Rect() As Rectangle
Get
Return rec
End Get
Set(ByVal value As Rectangle)
rec = value
End Set
End Property
Public Property AllRadius() As Integer
Get
Return d
End Get
Set(ByVal value As Integer)
If value > 0 Then
d = value
d1 = d
d2 = d
d3 = d
d4 = d
Else
Throw New Exception("Radius must be greator than zero 0.")
End If
End Set
End Property
Public Property TopLeftRadius() As Integer
Get
Return d1
End Get
Set(ByVal value As Integer)
If value > 0 Then
d1 = value
Else
Throw New Exception("Radius must be greator than zero 0.")
End If
End Set
End Property
Public Property TopRightRadius() As Integer
Get
Return d2
End Get
Set(ByVal value As Integer)
If value > 0 Then
d2 = value
Else
Throw New Exception("Radius must be greator than zero 0.")
End If
End Set
End Property
Public Property BottomRightRadius() As Integer
Get
Return d3
End Get
Set(ByVal value As Integer)
If value > 0 Then
d1 = value
Else
Throw New Exception("Radius must be greator than zero 0.")
End If
End Set
End Property
Public Property BottomLeftRadius() As Integer
Get
Return d4
End Get
Set(ByVal value As Integer)
If value > 0 Then
d1 = value
Else
Throw New Exception("Radius must be greator than zero 0.")
End If
End Set
End Property
#End Region
#Region "Constructors"
Public Sub New(ByVal rect As Rectangle, ByVal AllRad As Integer)
If Not rect.IsEmpty Then
rec = rect
Else
Throw New Exception("parameter rect is an empty rectangle .")
End If
AllRadius = AllRad
End Sub
Public Sub New(ByVal rect As Rectangle, ByVal TopLeftRad As Integer, ByVal TopRightRad As Integer, ByVal BottomRightRad As Integer, ByVal BottomLeftRad As Integer)
If Not rect.IsEmpty Then
rec = rect
Else
Throw New Exception("parameter rect is an empty rectangle .")
End If
Me.d = -1
If TopLeftRad > 0 AndAlso TopRightRad > 0 AndAlso BottomRightRad > 0 AndAlso BottomLeftRad > 0 Then
Me.d1 = TopLeftRad
Me.d2 = TopRightRad
Me.d3 = BottomRightRad
Me.d4 = BottomLeftRad
Else
Throw New Exception("Radius must be greator than zero 0.")
End If
End Sub
#End Region
#Region "Functions"
Public Function GetPath() As GraphicsPath
Dim path As New GraphicsPath
If Me.AllRadius = 1 Then
path.AddRectangle(Me.Rect)
Else
Dim arcRect As Rectangle = New Rectangle(rec.Location, New Size(d1, d1))
path.AddArc(arcRect, 180, 90)
arcRect.X = rec.Right - d2
arcRect.Size = New Size(d2, d2)
path.AddArc(arcRect, 270, 90)
arcRect.X = rec.Right - d3
arcRect.Y = rec.Bottom - d3
arcRect.Size = New Size(d3, d3)
path.AddArc(arcRect, 0, 90)
arcRect.Y = rec.Bottom - d4
arcRect.X = rec.X
arcRect.Size = New Size(d4, d4)
path.AddArc(arcRect, 90, 90)
End If
path.CloseFigure()
Return path
End Function
Public Function IsTopNormal() As Boolean
Return (Me.TopLeftRadius + Me.TopRightRadius) \ 2 <= Me.rec.Width
End Function
Public Function IsLeftNormal() As Boolean
Return (Me.TopLeftRadius + Me.BottomLeftRadius) \ 2 <= Me.rec.Height
End Function
Public Function IsBottomNormal() As Boolean
Return (Me.BottomLeftRadius + Me.BottomRightRadius) \ 2 <= Me.rec.Width
End Function
Public Function IsRightNormal() As Boolean
Return (Me.BottomRightRadius + Me.TopRightRadius) \ 2 <= Me.rec.Height
End Function
Public Function IsNormal() As Boolean
Return Me.IsBottomNormal AndAlso Me.IsLeftNormal AndAlso Me.IsRightNormal AndAlso Me.IsTopNormal
End Function
Public Function GetMinimumNormalWidth() As Integer
Return Math.Max((Me.TopRightRadius + Me.TopLeftRadius) \ 2, (Me.BottomRightRadius + Me.BottomLeftRadius) \ 2)
End Function
Public Function GetMinimumNormalHeight() As Integer
Return Math.Max((Me.TopRightRadius + Me.BottomRightRadius) \ 2, (Me.TopLeftRadius + Me.BottomLeftRadius) \ 2)
End Function
Public Function GetMinimumNormalSize() As Size
Return New Size(Me.GetMinimumNormalWidth, Me.GetMinimumNormalHeight)
End Function
#End Region
End Structure