vb.net 在文本框中查找并删除一行

vb.net Find and REMOVE a line in a textbox

我在尝试让我的代码工作时感到非常沮丧。

我正在尝试将列表框中的选定项目也从文本框中删除。

准备删除文本;

删除了文字; 但它仍然在文本框中。

这是我的代码

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            ListBox1.Items.Add(TextBox1.Text)
            TextBox2.Text += TextBox1.Text & vbNewLine
        End Sub
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            ListBox1.Items.Remove(ListBox1.SelectedItem)
'
'//HOW TO REMOVE THE SELECTED TEXT IN THE LISTBOX ALSO REMOVED IN THE TEXTBOX2??
'
'
        End Sub
        Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
            Dim filenames As String = "C:\log\log.txt"
            My.Computer.FileSystem.WriteAllText(filenames, TextBox2.Text, False)
        End Sub
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim filenames As String = "C:\log\log.txt"
            If My.Computer.FileSystem.FileExists(filenames) Then
                TextBox2.Text = My.Computer.FileSystem.ReadAllText(filenames)
                Dim items()
                items = TextBox2.Lines()
                For Each item In items
                    ListBox1.Items.Add(item)
                Next
            End If
        End Sub
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            Clipboard.SetText(ListBox1.SelectedItem)
        End Sub
    End Class

最糟糕的是,每次我尝试在线查找时,都没有错误,直到我单击显示 'Value Cannot Be Null' 的按钮 每次都这样。

拜托,在你按下 -1 按钮之前,至少告诉我原因。我是新手。

这应该适合你

Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    TextBox1.Text = TextBox1.Text.Replace(ListBox1.Items(ListBox1.SelectedIndex), Nothing)
    ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
End Sub

结束Class