【问题标题】:VB.NET Controls Not VisibleVB.NET 控件不可见
【发布时间】:2012-04-10 11:00:11
【问题描述】:

我正在尝试查看Me.Controls 中的所有标签,以及何时使用:

For Each Control As Label In Me.Controls.OfType(Of Label)()
    MsgBox(Control.Name.ToString)
Next

它只显示没有被重命名的标签。我在这里做错了吗?

【问题讨论】:

  • 现在重新阅读您的问题。您的问题没有提及有关您的标题“控件不可见”的任何内容。

标签: vb.net winforms controls


【解决方案1】:

在大多数情况下,您的代码看起来是正确的,除非您在其他容器控件(如 Panels 和 GroupBoxes)中有标签。在这种情况下,您也需要遍历这些容器。

这是一个例子:

Dim allContainers As New Stack(Of Control)
allContainers.Push(Me)
While allContainers.Count > 0
  For Each item As Control In allContainers.Pop.Controls
    If item.Controls.Count > 0 Then
      allContainers.Push(item)
    End If
    If TypeOf item Is Label Then
      MessageBox.Show("Label.Name = " + item.Name)
    End If
  Next
End While

【讨论】:

  • 很好,这正是问题所在!谢谢!
猜你喜欢
  • 1970-01-01
  • 2011-09-12
  • 1970-01-01
  • 1970-01-01
  • 2013-07-02
  • 1970-01-01
  • 2019-04-30
  • 1970-01-01
  • 2012-01-06
相关资源
最近更新 更多