Delete a specific line in a .NET RichTextBox

后端 未结 9 1523
后悔当初
后悔当初 2021-01-19 15:08

How can I delete a specific line of text in a RichTextBox ?

9条回答
  •  无人及你
    2021-01-19 15:29

    Try this:

    Dim lst As New ListBox  
            Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
                Me.Controls.Add(lst)  
                For Each cosa As String In Me.RichTextBox1.Lines  
                    lst.Items.Add(cosa)  
                Next  
                lst.Items.RemoveAt(2) 'the integer value must be the line that you want to remove -1  
                Me.RichTextBox1.Text = String.Empty  
                For i As Integer = 0 To lst.Items.Count - 1  
                    If Me.RichTextBox1.Text = String.Empty Then  
                        Me.RichTextBox1.Text = lst.Items.Item(i)  
                    Else  
                        MeMe.RichTextBox1.Text = Me.RichTextBox1.Text & Environment.NewLine & lst.Items.Item(i).ToString  
                    End If  
                Next  
            End Sub
    

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/63647481-743d-4e55-9043-e0db5106a03a/

提交回复
热议问题