简体   繁体   English

VB.NET控件不可见

[英]VB.NET Controls Not Visible

I am trying to see all the labels in Me.Controls and when I use: 我想看看Me.Controls所有标签,当我使用时:

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

it only shows the labels that have NOT been renamed. 它仅显示尚未重命名的标签。 Am I doing something wrong here? 我在这里做错了吗?

For the most part, your code looks right, unless you have labels inside other container controls like Panels and GroupBoxes. 在大多数情况下,您的代码看起来是正确的,除非您在其他容器控件(如Panels和GroupBoxes)中有标签。 In which case, you would need to loop through those containers, too. 在这种情况下,您也需要遍历这些容器。

Here is an example: 这是一个例子:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM