Schönen guten Taaaaaaaag,
Ich arbeite zurzeit an einer "art" Textbox und mir ist da was aufgefallen.
Der Code
funktioniert irgendwie nicht, nachdem ich mir
das
es 100 zurück)
Ja gut, ist das ein Bug oder mache ich etwas flasch?
Der gasammte Code nochmal:
Spoiler anzeigen
EDIT:
Wen ich ALT drücke funktioniert es komischerweise....
Grußartige grüße, Luca
Ich arbeite zurzeit an einer "art" Textbox und mir ist da was aufgefallen.
Der Code
funktioniert irgendwie nicht, nachdem ich mir
Me.Text.Length
mal anzeigen lassen habe, habe ich gemerkt,das
Me.Text.Length
immer zurückgibt, wie lang der String mal war (also wenn es mal 100 Zeichen waren gibtes 100 zurück)
Ja gut, ist das ein Bug oder mache ich etwas flasch?
Der gasammte Code nochmal:
VB.NET-Quellcode
- Public Class BetterTextArea
- Inherits Control
- Sub New()
- MyBase.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
- MyBase.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
- MyBase.SetStyle(ControlStyles.UserMouse, True)
- MyBase.SetStyle(ControlStyles.UserPaint, True)
- MyBase.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
- End Sub
- Private Sub PaintEvent(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
- DrawRoundedRectangle(e.Graphics, New Rectangle(0, 0, Me.Width - 1, Me.Height - 1), 6, Color.Black)
- Dim pos As New Point(Me.Height / 2, Me.Width / 2)
- Dim font As New Font("Segoe Print", 20, FontStyle.Regular, GraphicsUnit.Pixel)
- Dim size = e.Graphics.MeasureString(Text, font)
- Dim texPos As New Point(0, (Me.Height - size.Height) / 2)
- If (size.Width > Me.Size.Width) Then
- texPos.X -= size.Width - Me.Size.Width
- End If
- e.Graphics.DrawString(Me.Text, font, Brushes.Black, texPos)
- End Sub
- Private Sub BetterTextArea_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
- If e.KeyCode = Keys.V And e.Control Then
- If isCopyPasteAllowed Then
- Me.Text += Clipboard.GetText
- Invalidate()
- Else
- With New Audio
- .PlaySystemSound(Media.SystemSounds.Exclamation)
- End With
- End If
- ElseIf e.KeyCode = Keys.Back Then
- If e.Control Then
- Me.Text = ""
- Invalidate()
- ElseIf Me.Text.Length > 0 Then
- Console.WriteLine(Me.Text.Length)
- Me.Text = Me.Text.Substring(0, Me.Text.Length - 1)
- Invalidate()
- End If
- End If
- End Sub
- Private Sub BetterTextArea_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Me.KeyPress
- Dim kb As New Keyboard
- If Not kb.CtrlKeyDown Then
- Dim c = e.KeyChar
- Me.Text &= c
- Invalidate()
- End If
- End Sub
- Private isCopyPasteAllowed As Boolean = True
- <Category("Behavior")>
- Public Property CopyPasteAllowed() As Boolean
- Get
- Return isCopyPasteAllowed
- End Get
- Set(ByVal value As Boolean)
- isCopyPasteAllowed = value
- End Set
- End Property
- End Class
EDIT:
Wen ich ALT drücke funktioniert es komischerweise....
Grußartige grüße, Luca
こんにちわ
Achte beim stellen von Fragen auf eine genaue Fragestellung, mir passiert das selbst häufig, andere können dir dann nicht so gut helfen.
Achte beim stellen von Fragen auf eine genaue Fragestellung, mir passiert das selbst häufig, andere können dir dann nicht so gut helfen.
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „LuaX“ ()