So, hab jetzt den Code (sehr ausführlich):
Imports System
Imports System.Drawing
Public Class MyGroupbox : Inherits System.Windows.Forms.Panel
Private _linewidth As Byte = 1
Private _color As Color = Color.Black
Private antialias As Boolean = True
Private _myText As String
Public Property LineWidth() As Byte
Get
Return _linewidth
End Get
Set(ByVal value As Byte)
_linewidth = value
End Set
End Property
Public Property Color() As Color
Get
Return _color
End Get
Set(ByVal value As Color)
_color = value
End Set
End Property
Public Property AntiAliasing() As Boolean
Get
Return antialias
End Get
Set(ByVal value As Boolean)
antialias = value
End Set
End Property
Public Property myText() As String
Get
Return _myText
End Get
Set(ByVal value As String)
_myText = value
End Set
End Property
Private Sub MyGroupbox_Paint(ByVal sender As Object, ByVal e As _
System.Windows.Forms.PaintEventArgs) Handles Me.Paint
If antialias Then e.Graphics.SmoothingMode = _
Drawing2D.SmoothingMode.AntiAlias
'erst muss mal die Breite und Höhe des Textes ausgerechnet werden,
' sonst is des ja kei richtige GroupBox
Dim text_breite As Integer = e.Graphics.MeasureString(_myText, _
Me.Font).Width
Dim text_höhe As Integer = e.Graphics.MeasureString(_myText, _
Me.Font).Height
'Jetzt werden die Koordinaten der Endpunkte gerechnet
'Zuerst links oben
Dim links_oben As Point = New Point(0, 1 + Int(text_höhe / 2))
'Jetzt der Punkt weiter rechts
Dim links_oben2 As Point = New Point(3, 1 + Int(text_höhe / 2))
'Hier soll der Text beginnen:
Dim links_oben3 As Point = New Point(4, 1)
'Eckpunkt oben
Dim rechts_oben As Point = New Point(Me.Width - 1, 1 + Int(text_höhe / _
2))
'Ende des Textes
Dim rechts_oben2 As Point = New Point(2 + text_breite, 1 + Int( _
text_höhe / 2))
'Eckpunkte unten
Dim links_unten As Point = New Point(0, Me.Height - 1)
Dim rechts_unten As Point = New Point(Me.Width - 1, Me.Height - 1)
'Jetzt kommt das große Zeichnen
e.Graphics.DrawLine(New Pen(_color, _linewidth), links_oben, _
links_oben2)
e.Graphics.DrawLine(New Pen(_color, _linewidth), rechts_oben, _
rechts_oben2)
e.Graphics.DrawLine(New Pen(_color, _linewidth), links_oben, _
links_unten)
e.Graphics.DrawLine(New Pen(_color, _linewidth), rechts_oben, _
rechts_unten)
e.Graphics.DrawLine(New Pen(_color, _linewidth), links_unten, _
rechts_unten)
e.Graphics.DrawString(_myText, Me.Font, Brushes.Black, links_oben3)
'Padding bestimmen:
Me.Padding = New System.Windows.Forms.Padding(1, 2 + text_höhe, 1, 1)
'abschließen
e.Dispose()
End Sub
End Class _______________
Meine HP: http://www.tenschman.de/ |