Imports System.Drawing.Drawing2D
Public Class GroupBoxEx
Inherits System.Windows.Forms.GroupBox
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'UserControl overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
components = New System.ComponentModel.Container
End Sub
#End Region
#Region " Properties "
Private cBorder As Color = Color.Black
Public Property BorderColor() As Color
Get
Return cBorder
End Get
Set(ByVal Value As Color)
cBorder = Value
Invalidate()
End Set
End Property
#End Region
#Region " Paint "
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
'Draw the border
Dim p As New Pen(cBorder, 1)
Dim gp As New GraphicsPath
gp.AddArc(New Rectangle(0, 9, 16, 16), 180, 90)
gp.AddArc(New Rectangle(Width - 17, 9, 16, 16), 270, 90)
gp.AddArc(New Rectangle(Width - 17, Height - 18, 16, 16), 0, 90)
gp.AddArc(New Rectangle(0, Height - 18, 16, 16), 90, 90)
gp.AddLine(0, 17, 0, Height - 17)
e.Graphics.FillPath(New SolidBrush(BackColor), gp)
e.Graphics.DrawPath(p, gp)
'Draw the caption
Dim sf As SizeF = e.Graphics.MeasureString(Text, Font)
e.Graphics.FillRectangle(New SolidBrush(Color.Transparent), 16, 2, sf.Width, sf.Height + 4)
e.Graphics.DrawLine(New Pen(BackColor), 16, 9, 16 + sf.Width, 9)
e.Graphics.DrawString(Text, Font, New SolidBrush(ForeColor), 18, 3)
gp.Dispose()
p.Dispose()
End Sub
Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
pevent.Graphics.FillRectangle(New SolidBrush(Parent.BackColor), pevent.ClipRectangle)
End Sub
#End Region
End Class