本文介绍了循环访问某些控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下循环:


Dim objPanel作为面板


每个objPanel In Me.Controls


''在这里做点什么


下一页


我的循环遇到一个不是a的控件时收到错误小组

控制。


我只想对我的表格上的Panel控件执行操作,并跳过任何

其他类型的控制。


有没有办法只通过Panel控件循环?

I have the following loop:

Dim objPanel As Panel

For Each objPanel In Me.Controls

''do something here

Next

I receive an error when my loop encounters a control that is not a Panel
control.

I only want to perform actions on the Panel controls on my form and skip any
other type of control.

Is there a way to loop only through the Panel controls?

推荐答案






For Each ctl作为Control In Me.Controls

如果TypeOf ctl是Panel那么

objPanel = CType(ctl,Panel)

''在这里做点什么

结束如果

下一页


Mattias


-

Mattias Sj?g ren [MVP] mattias @ mvps.org
|

请回复到新闻组。



For Each ctl As Control In Me.Controls
If TypeOf ctl Is Panel Then
objPanel = CType(ctl, Panel)
''do something here
End If
Next

Mattias

--
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.




这篇关于循环访问某些控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 13:30