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

vb.net查找并删除文本框中的一行,vb.net,replace,textbox,listbox,find,Vb.net,Replace,Textbox,Listbox,Find,我很沮丧试图让我的代码工作 我正在尝试删除列表框中的选定项以及文本框中的选定项 准备删除文本; 删除文本; 但它仍然在文本框中 这是我的密码 Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ListBox1.Items.Add(TextBox1.Text) TextBo

我很沮丧试图让我的代码工作

我正在尝试删除列表框中的选定项以及文本框中的选定项

准备删除文本;

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

这是我的密码

    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
最糟糕的是,每次我尝试在线查找时,都没有错误,直到我单击“值不能为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

期末班

这应该适合你

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

End Class

请注意,只有在列表框中没有任何两次相同的项时,此选项才会起作用。。。但是如果这对你来说没问题,那就行了是的,这是真的,列表框将删除选定的索引,但是文本框将丢失该字符串的所有内容。对不起,我的英语很抱歉,我知道只有在列表框中没有任何两次相同的项目时,这才有效。。。但是如果这对你来说没问题,那就行了是的,这是真的,列表框将删除选定的索引,但是文本框将丢失该字符串的所有内容。对不起,我的英语不好