2015-06-20 169 views
-2

我需要删除最后一行richtextbox。我尝试了几种方法。但没有任何工作。请人帮我删除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) 
+0

添加你已经尝试了什么,添加相关标签 – sinhayash

+0

显示你已经尝试过什么,并描述它是如何未能按预期运行。 – Filburt

+0

For t = Len(texto)To 0 Step -1 If Mid(texto,t,1)= vbCr Then c = c + 1 'texto = Mid(texto,1,t - 1)do end如果 ' 如果C = 2然后退出对于 接着 RichTextBox2.Text =左$(texto,叔 - 1) –

回答

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