Я смог сделать это с помощью пользовательского элемента управления.Это выглядит как во время разработки и выполнения:
![Separator Control](https://i.stack.imgur.com/2y1fK.png)
Вот код:
Partial Public Class Line
Inherits Control
Private Sub Line_Paint(Sender As Line, e As PaintEventArgs) Handles Me.Paint
Dim oBackground As Rectangle
Dim oTextSize As Size
Dim _
iX,
iY As Integer
oTextSize = TextRenderer.MeasureText(Me.Text, Me.Font)
Me.Height = oTextSize.Height + 3
iX = 1
iY = Me.Height / 2
Using oPen As New Pen(Me.LineColor)
e.Graphics.DrawLine(oPen, iX, iY, Me.Width - iX - 1, iY)
End Using
Using oPen As New Pen(Color.White)
e.Graphics.DrawLine(oPen, iX + 1, iY + 1, Me.Width - iX, iY + 1)
End Using
If oTextSize.Height > 0 Then
Using oBrush As New SolidBrush(Me.BackColor)
oBackground = New Rectangle(7, 1, oTextSize.Width - 2, oTextSize.Height)
e.Graphics.FillRectangle(oBrush, oBackground)
End Using
Using oBrush As New SolidBrush(Me.ForeColor)
e.Graphics.DrawString(Me.Text, Me.Font, oBrush, 7, 1)
End Using
End If
End Sub
<DefaultValue(GetType(Color), "System.Drawing.SystemColors.ActiveBorder")>
<Description("The color of the line.")>
<Browsable(True)>
<Category("Appearance")>
Public Property LineColor As Color
Get
Return Me._LineColor
End Get
Set(Value As Color)
Me._LineColor = Value
Me.Invalidate()
End Set
End Property
Private Property _LineColor As Color = SystemColors.ActiveBorder
End Class