Making buttons disappear depending on the size of a list

做~自己de王妃 提交于 2019-12-25 17:43:10

问题


I am trying to make a button disappear off the screen when the size of a list that is being filled by the user reaches a size of lets say 3 items.

The button is for "adding a new person" but once the list is full i don't want that to be an option to add another person to the list.

I have tried the following code but the program doesn't run

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

could someone please help me? the program doesn't even open. I just want the button to go away when the number of elements in a list is greater than a specific number lets just say 3 for now

I can also include the rest of the code for my program


回答1:


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


来源:https://stackoverflow.com/questions/42468424/making-buttons-disappear-depending-on-the-size-of-a-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!