使按钮消失取决于列表的大小

时间:2017-02-26 12:22:41

标签: vb.net visual-studio-2010 visual-studio-2012

当用户填写的列表大小达到3个项目的大小时,我试图让按钮从屏幕上消失。

该按钮用于“添加新人”,但是一旦列表已满,我不希望将其添加到列表中。

我尝试过以下代码,但程序没有运行

Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove

    If inputNames.Count >= 3 Then   'inputnames is the name of the list
        Button1.Visible = False     'button 1 is the add a new person button
    End If
End Sub
有人可以帮帮我吗?该计划甚至没有公开。 我只是希望当列表中的元素数量大于特定数字时,按钮会消失,现在只需说3

我还可以包含我的程序的其余代码

1 个答案:

答案 0 :(得分:0)

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    If ListBox1.Items.Count >= 2 Then
        'your add code
        Button2.Visible = False
    End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    If ListBox1.Items.Count >= 2 Then
        Button2.Visible = False
    End If
End Sub