【问题标题】:Making buttons disappear depending on the size of a list根据列表的大小使按钮消失
【发布时间】:2017-07-17 01:02:50
【问题描述】:

当用户填写的列表大小达到 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

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

【问题讨论】:

  • 不编译?启动后直接崩溃?冻结?不跑是什么意思?将鼠标指针移到表单上后可能会直接崩溃?首次使用鼠标指针输入时,请确保 inputNames 不是 Nothing

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


【解决方案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

【讨论】:

  • 如果您不使用列表框,请正确编写您使用的控件
  • “列表”可能是List(Of T)。无论哪种方式,他在问题中都用它的名字来称呼它。
  • Inputheight.items.count 似乎也不起作用。仅输入项目时不会弹出项目的东西
  • @JordanH :那是因为Items 只是ListBox 的子属性。对于列表,它只是 .Count
猜你喜欢
  • 1970-01-01
  • 2011-09-08
  • 2013-12-06
  • 2017-12-02
  • 2011-09-09
  • 2014-12-28
  • 1970-01-01
  • 2022-10-17
  • 2022-12-10
相关资源
最近更新 更多