注册 登录
编程论坛 VB.NET论坛

求问各位大神如何做下面的题目

三竖 发布于 2020-05-15 20:28, 1729 次点击
只有本站会员才能查看附件,请 登录
2 回复
#2
gbhytg2020-06-02 18:24
你可以试试这个,使用vb2012做的
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        TextBox1.Focus()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If TextBox1.TextLength > 0 Then
            ListBox1.Items.Add(TextBox1.Text)
            TextBox1.Clear()
            TextBox1.Focus()
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim i As Integer = 0
        If TextBox1.TextLength > 0 Then
            If ListBox1.Items.Count > 0 Then
                For i = 0 To ListBox1.Items.Count - 1
                    ListBox1.SelectedIndex = i
                    ListBox1.Items.Remove(TextBox1.Text)
                    Exit For
                Next
            End If
        End If
    End Sub
End Class
#3
moou2020-09-01 14:02
程序代码:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For i = 0 To 2
            ListBox1.Items.Add(InputBox("添加第" & i + 1 & "个项目"))
        Next
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim inputStr As String = InputBox("输入要删除的数据")

        For i = 0 To ListBox1.Items.Count - 1
            If ListBox1.Items(i).ToString = inputStr Then
                ListBox1.Items.RemoveAt(i)
                Exit For
            End If
        Next
    End Sub


我看的描述为啥跟下面的Text1没啥关系啊
1