删除richtextbox的最后一行

时间:2015-06-20 09:25:23

标签: vb.net visual-studio-2013

我需要删除richtextbox的最后一行。我尝试了几种方法。但没有任何效果。有人请帮助我

For t = Len(texto) To 0 Step -1
        If Mid(texto, t, 1) = vbCr Then
            c = c + 1
            'texto = Mid(texto, 1, t - 1) don't
        End If
        '
        If c = 2 Then Exit For
    Next

    RichTextBox2.Text = Left$(texto, t - 1)

1 个答案:

答案 0 :(得分:0)

Dim lastLine As Integer = UBound(RichTextBox2.Lines)
If lastLine > -1 Then
    Dim newLines() As String
    For i As Integer = 0 To lastLine
        If i < lastLine Then
            ReDim Preserve newLines(i)
            newLines(i) = RichTextBox2.Lines(i)
        End If
    Next
    RichTextBox2.Lines = newLines
End If