如何循环tabcontrol1或tabpage中的所有控件? [英] How do I loop all controls in the tabcontrol1 or tabpage ?

查看:158
本文介绍了如何循环tabcontrol1或tabpage中的所有控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

For Each cControl In Me.Controls
  If (TypeOf cControl Is TextBox) Then
          End If
          If (TypeOf cControl Is CheckBox) Then
          End If
          If (TypeOf cControl Is ComboBox) Then
          End If
          If (TypeOf cControl Is RadioButton) Then
          End If
        next cControl





我尝试了什么:



尽我所能努力提高质量但是?



What I have tried:

tryed me best effort to make a quality but ?

推荐答案

不太确定您的问题,因为您显示的代码将起作用,但是如果您在像tabcontrol这样的容器中有控件,则需要单独迭代这些控件,因为它们不是你正在迭代的容器。



最简单的方法是使用一个递归函数将容器控件作为参数传递,当它发现一个控件让子控件传递给控件时调用它自己争论。



快示例(未经过我头脑的测试)。



Not quite sure of your question as the code you show will work, however if you have controls inside a container like a tabcontrol you need to iterate those controls separately as they are not members of the container you are iterating.

Easiest way is to use a recursive function passing the container control as argument and calling itself when it find a control has children passing that control as argument.

Quick example (not tested written of the top of my head).

public sub WalkControls(TopControl as Control)
   For Each x As Control In TopControl.Controls
       If x.HasChildren Then
          WalkControls(x)
       Else
'
' Do what you want to do with the control
'
       End If
   Next
End sub


这篇关于如何循环tabcontrol1或tabpage中的所有控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆