Edit Hat sich Erledigt...
Hier Für denen die sowas suchen.
Dynamische Groupbox Während der Laufzeit Stylen.
'Groupbox Herstellen
Neue Groupbox Classe Herstellen
*Topic verschoben*
Hier Für denen die sowas suchen.
Dynamische Groupbox Während der Laufzeit Stylen.
'Groupbox Herstellen
VB.NET-Quellcode
- Dim GroupBoxBordercolor As Color
- If Das= "....." Then
- GroupBoxBordercolor = Color.Green
- End If
- GroupBoxes(IdCount) = New MyGroupBox With { 'IdCounter Ist Die Nummerierung der Groupboxen
- .Name = "GroupBox" & IdCount,
- .Left = 10 + 1 * 360,
- .Top = 1 + 1 * 2,
- .Size = New Size(350, 200),
- .Text = Username,
- .BorderColor = GroupBoxBordercolor,
- .ForeColor = Color.Black
- }
- GroupBoxes(IdCount).BackColor = Color.Transparent ' Transparentes Hintergrund
- Form1.Tabpage1.Controls.Add(GroupBoxes(IdCount))
Neue Groupbox Classe Herstellen
VB.NET-Quellcode
- Public Class MyGroupBox
- Inherits GroupBox
- 'Create the Property backing fields
- Private _BorderPen As Pen
- Private _BackgroundBrush As SolidBrush
- Private _TextBrush As SolidBrush
- 'In the constructor set the default colors you want to the brushes and pens of the property backing feilds
- Public Sub New()
- MyBase.ForeColor = Color.Red 'set forecolor to red
- _BorderPen = New Pen(Color.Blue)
- _BackgroundBrush = New SolidBrush(Me.BackColor)
- _TextBrush = New SolidBrush(Me.ForeColor)
- End Sub
- Public Property BorderColor() As Color
- Get
- Return _BorderPen.Color
- End Get
- Set(ByVal value As Color)
- _BorderPen.Color = value
- Me.Refresh()
- End Set
- End Property
- Public Overrides Property ForeColor() As System.Drawing.Color
- Get
- Return MyBase.ForeColor
- End Get
- Set(ByVal value As System.Drawing.Color)
- MyBase.ForeColor = value
- _TextBrush.Color = value
- End Set
- End Property
- Public Overrides Property BackColor() As System.Drawing.Color
- Get
- Return MyBase.BackColor
- End Get
- Set(ByVal value As System.Drawing.Color)
- MyBase.BackColor = value
- _BackgroundBrush.Color = value
- End Set
- End Property
- Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
- Dim strSize As SizeF = e.Graphics.MeasureString(Me.Text, Me.Font)
- Dim rect As New Rectangle(0, CInt(CInt(strSize.Height) \ 2), Me.Width - 1, Me.Height - CInt(CInt(strSize.Height) \ 2) - 1)
- ' Clear text and border
- e.Graphics.FillRectangle(_BackgroundBrush, 0, 0, Me.Width, Me.Height)
- ' Draw text
- e.Graphics.DrawString(Me.Text, Me.Font, _TextBrush, Me.Padding.Left, 0)
- ' Drawing Border
- 'Left
- e.Graphics.DrawLine(_BorderPen, rect.Location, New Point(rect.X, rect.Y + rect.Height))
- 'Right
- e.Graphics.DrawLine(_BorderPen, New Point(rect.X + rect.Width, rect.Y), New Point(rect.X + rect.Width, rect.Y + rect.Height))
- 'Bottom
- e.Graphics.DrawLine(_BorderPen, New Point(rect.X, rect.Y + rect.Height), New Point(rect.X + rect.Width, rect.Y + rect.Height))
- 'Top1
- e.Graphics.DrawLine(_BorderPen, New Point(rect.X, rect.Y), New Point(rect.X + Me.Padding.Left, rect.Y))
- 'Top2
- e.Graphics.DrawLine(_BorderPen, New Point(rect.X + Me.Padding.Left + CInt(strSize.Width), rect.Y), New Point(rect.X + rect.Width, rect.Y))
- End Sub
- Protected Overrides Sub Dispose(ByVal disposing As Boolean)
- 'Dispose of the New brushes and pens that where created for the property backing feilds
- _BorderPen.Dispose()
- _BackgroundBrush.Dispose()
- _TextBrush.Dispose()
- MyBase.Dispose(disposing)
- End Sub
- End Class
*Topic verschoben*
Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „Marcus Gräfe“ ()