Moin, ich hab ein Control erstellt in dem eine Textbox drinnen ist, jetzt möchte ich gerne über die
Textbox Zeichnen oder innen drin, jetzt meine frage ob da jemand eine Lösung zu hat bzw ob es überhaupt
möglich ist, ich hab schon diverse Themen durchsucht aber nichts hilfreiches
gefunden, über ein Beispiel würde ich mich sehr freuen.
Hier die Textbox:
Spoiler anzeigen
Lg Steve
Textbox Zeichnen oder innen drin, jetzt meine frage ob da jemand eine Lösung zu hat bzw ob es überhaupt
möglich ist, ich hab schon diverse Themen durchsucht aber nichts hilfreiches
gefunden, über ein Beispiel würde ich mich sehr freuen.
Hier die Textbox:
VB.NET-Quellcode
- Public Class XTextBox
- Inherits Control
- Dim WithEvents TxtBox As New TextBox
- Dim G As Graphics
- Sub New()
- MyBase.New()
- SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint, True)
- SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
- BackColor = Color.FromArgb(50, 50, 50)
- ForeColor = Color.FromArgb(100, 100, 100)
- Size = New Size(150, 30)
- Font = New Font("Arial", 9, FontStyle.Regular)
- NewTextBox() : Controls.Add(TxtBox)
- End Sub
- Sub NewTextBox()
- With TxtBox
- .Multiline = False
- .ForeColor = Color.FromArgb(100, 100, 100)
- .BackColor = Color.FromArgb(50, 50, 50)
- .Text = String.Empty
- .TextAlign = HorizontalAlignment.Left
- .BorderStyle = BorderStyle.None
- .Font = Font
- .Size = New Size(Width - 16, TxtBox.Height)
- .Location = New Point(8, 8)
- .UseSystemPasswordChar = UseSystemPasswordChar
- End With
- End Sub
- <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> Public Shadows Property Multiline() As Boolean
- Get
- Return False
- End Get
- Set(ByVal value As Boolean)
- End Set
- End Property
- Private _FocusColor As Color = Color.FromArgb(70, 70, 70)
- Public Property FocusColor() As Color
- Get
- Return _FocusColor
- End Get
- Set(ByVal value As Color)
- _FocusColor = value
- End Set
- End Property
- Private _FocusHighLight As Boolean = True
- Public Property FocusHighLight() As Boolean
- Get
- Return _FocusHighLight
- End Get
- Set(ByVal value As Boolean)
- _FocusHighLight = value
- End Set
- End Property
- Private _TextAlignment As HorizontalAlignment
- Public Shadows Property TextAlignment() As HorizontalAlignment
- Get
- Return _TextAlignment
- End Get
- Set(ByVal value As HorizontalAlignment)
- _TextAlignment = value
- TxtBox.TextAlign = value
- Invalidate()
- End Set
- End Property
- Private _UseSystemPasswordChar As Boolean = False
- Public Shadows Property UseSystemPasswordChar() As Boolean
- Get
- Return _UseSystemPasswordChar
- End Get
- Set(ByVal value As Boolean)
- _UseSystemPasswordChar = value
- TxtBox.UseSystemPasswordChar = UseSystemPasswordChar
- Invalidate()
- End Set
- End Property
- Private _MaxLength As Integer = 1000
- Public Shadows Property MaxLength() As Integer
- Get
- Return _MaxLength
- End Get
- Set(ByVal value As Integer)
- _MaxLength = value
- TxtBox.MaxLength = MaxLength
- Invalidate()
- End Set
- End Property
- Private Sub KeyHandel(sender As Object, e As KeyEventArgs) Handles TxtBox.KeyDown
- MyBase.OnKeyDown(e)
- End Sub
- Protected Overrides Sub OnReSize(ByVal e As System.EventArgs)
- TxtBox.Size = New Size(Width - 16, TxtBox.Height)
- TxtBox.Location = New Point(8, CInt(Height / 2 - (TxtBox.Size.Height / 2)))
- Invalidate()
- End Sub
- Protected Overrides Sub OnForeColorChanged(ByVal e As System.EventArgs)
- TxtBox.ForeColor = ForeColor
- Invalidate()
- End Sub
- Protected Overrides Sub OnFontChanged(ByVal e As System.EventArgs)
- TxtBox.Font = Font
- TxtBox.Location = New Point(8, CInt(Height / 2 - (TxtBox.Size.Height / 2)))
- Invalidate()
- End Sub
- Protected Overrides Sub OnMouseClick(ByVal e As MouseEventArgs)
- TxtBox.Focus()
- End Sub
- Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
- MyBase.OnGotFocus(e)
- TxtBox.Focus()
- End Sub
- Sub TextChangeTxtBox() Handles TxtBox.TextChanged
- Text = TxtBox.Text
- End Sub
- Sub TextChange() Handles MyBase.TextChanged
- TxtBox.Text = Text
- End Sub
- Dim IsEnter As Boolean = False
- Protected Overrides Sub OnEnter(ByVal e As System.EventArgs)
- If _FocusHighLight = True Then
- IsEnter = True
- Invalidate()
- End If
- MyBase.OnEnter(e)
- End Sub
- Protected Overrides Sub OnLeave(ByVal e As System.EventArgs)
- If _FocusHighLight = True Then
- IsEnter = False
- Invalidate()
- End If
- MyBase.OnLeave(e)
- End Sub
- Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
- G = e.Graphics : G.SmoothingMode = SmoothingMode.AntiAlias
- G.Clear(BackColor)
- G.FillRectangle(New SolidBrush(Color.FromArgb(200, 80, 80, 80)), New Rectangle(0, 0, Width, CInt(Height / 2))) 'Schatten hinten
- G.FillRectangle(New SolidBrush(Color.FromArgb(50, 50, 50)), New Rectangle(3, 3, Width - 7, Height - 7)) 'Fläche Innen
- G.DrawRectangle(New Pen(Color.FromArgb(0, 0, 0)), New Rectangle(0, 0, Width - 1, Height - 1)) 'Umrandung außen
- G.DrawRectangle(New Pen(Color.FromArgb(0, 0, 0)), New Rectangle(3, 3, Width - 7, Height - 7)) 'Innen umrandung
- If IsEnter = True Then
- G.DrawRectangle(New Pen(_FocusColor), New Rectangle(0, 0, Width - 1, Height - 1))
- End If
- End Sub
- End Class
Lg Steve