How to get paste to work for pasting in text in a textbox?

24 views Asked by At

I have the following code to limit the number of characters to 70 per line and only allow 10 lines in a multi line textbox. It works fine.

But when I want to paste some text into the textbox...nothing appears in the textbox. How do I get paste to work in a textbox also?

Private Sub TextBox24_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox24.TextChanged

    Static txtPrev As String
    Dim MaxCharsPerLine As Integer = 70

    If TextBox24.Lines.GetUpperBound(0) >= 10 Then
        TextBox24.Text = txtPrev
        TextBox24.SelectionStart = TextBox24.Text.Length
    Else
        For i As Integer = 0 To TextBox24.Lines.GetUpperBound(0)
            If TextBox24.Lines(i).Length > MaxCharsPerLine Then
                TextBox24.Text = txtPrev
                TextBox24.SelectionStart = TextBox24.Text.Length
                Exit Sub
            End If
        Next

        txtPrev = TextBox24.Text
    End If
End Sub

I really didn't find anything related to this issue online.

0

There are 0 answers