【问题标题】:Get All Controls of winform? [duplicate]获取winform的所有控件? [复制]
【发布时间】:2014-09-07 18:21:40
【问题描述】:

我有一个包含许多表格布局面板、组框和流布局面板的表单,一个在另一个里面。我已经为每个文本框、标签和一些控件的标签设置了一个字符串值。
我怎样才能获得标签值为字符串的所有控件?

【问题讨论】:

  • 您要查找的单词是recursion
  • 如何使用它,因为每个 Panel 都有其 on ContainerContols 类型?
  • 我为此在 github.com/dotnet/winforms 上创建了一个API Proposal: Add Descendants property for Control。如果你喜欢它,请在那里投票。

标签: .net vb.net winforms forms


【解决方案1】:

表单的 Controls 属性是一个包含所有驻留在表单中的控件的数组。
同理,每个Container控件,如Panels、TabControl、etch。有它自己的 Controls 属性。 所以你可以使用这样的语句:

Dim Control As Windows.Forms.Control
For Each Control In Me.Controls
'Your logic Here  

If Control.GetType Is GetType(System.windows.Forms.Panel) Or ... 'Any Other Container Type control
Dim Nested As Windows.Forms.Control
For Each Nested In Control... 'Your logic Here
End

【讨论】:

    猜你喜欢
    • 2011-02-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 2010-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多