Hallo.
Ich würde gerne eine TextBox selbst zeichnen.
Momentan sieht der Code so aus:
Kann mir jemand sagen was da falsch ist?
Ich würde gerne eine TextBox selbst zeichnen.
Momentan sieht der Code so aus:
VB.NET-Quellcode
- Public Class OwnTextBox : Inherits TextBox
- Private Status As State = State.Normal
- Private Texto As String = String.Empty
- Private Fonto As Font = New Font("Lucida Grande", 10)
- Private Structure TextBoxState
- Public ReadOnly left, middle, right As Bitmap
- Public Sub New(left As Bitmap, middle As Bitmap, right As Bitmap)
- Me.left = left
- Me.middle = middle
- Me.right = right
- End Sub
- End Structure
- Private textboxStates As TextBoxState() = {New TextBoxState(My.Resources.TextBoxSideUnActivated, My.Resources.TextBoxMiddle, My.Resources.TextBoxSideUnActivated),
- New TextBoxState(My.Resources.TextBoxActivatedLinks, My.Resources.TextBoxActivatedMittle, My.Resources.TextBoxActivatedRechts)}
- Public Enum State
- Normal = 0
- Focused = 1
- End Enum
- Public Sub New()
- Me.DoubleBuffered = True
- Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
- Me.SetStyle(ControlStyles.FixedHeight, True)
- Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
- Me.SetStyle(ControlStyles.ResizeRedraw, True)
- Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
- End Sub
- Public Sub Redraw(ausgabe As Graphics)
- Dim gr As Graphics = ausgabe
- gr.Clear(Me.BackColor)
- Dim currtextboxstate As TextBoxState = textboxStates(Status)
- gr.DrawImage(currtextboxstate.left, 0, 0, currtextboxstate.left.Width, Me.Height)
- For i As Integer = 0 To 5
- gr.DrawImage(currtextboxstate.middle, 0, 0, currtextboxstate.middle.Width, Me.Height)
- Next
- gr.DrawImage(currtextboxstate.right, 0, 0, currtextboxstate.right.Width, Me.Height)
- End Sub
- <Browsable(True), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
- Public Overrides Property Font() As Font
- Get
- Return Fonto
- End Get
- Set(Font As Font)
- Fonto = Font
- Me.Invalidate()
- End Set
- End Property
- <Browsable(True), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
- Public Overrides Property Text() As String
- Get
- Return Texto
- End Get
- Set(value As String)
- Texto = value
- Me.Invalidate()
- End Set
- End Property
- Protected Overrides Sub OnLostFocus(e As EventArgs)
- MyBase.OnLostFocus(e)
- Status = State.Normal
- Me.Invalidate()
- End Sub
- Protected Overrides Sub OnGotFocus(e As EventArgs)
- MyBase.OnGotFocus(e)
- Status = State.Focused
- Me.Invalidate()
- End Sub
- Protected Overrides Sub OnPaint(pevent As System.Windows.Forms.PaintEventArgs)
- Redraw(pevent.Graphics)
- End Sub
- End Class
Kann mir jemand sagen was da falsch ist?
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Kevin Hombre“ ()