2015-06-20 172 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