问题
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