循环通过 vb.net 中的元素 [英] Looping though elements in vb.net

查看:34
本文介绍了循环通过 vb.net 中的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以循环遍历多个具有基于数字的名称的元素,并更改它们的属性?

Is there a way I can loop though multiple elements with number based names, changing their properties?

示例:

以下是我的表单中的一组元素示例:

Here are an example set of elements on my form:

Element1
Element2
Element3
Element4
Element5

这是我在想的那种事情:

This is the kind of thing i was thinking of:

For i = 1 To 5
    Element + i .BackColor = Color.Maroon 
Next

这只是因为我有大量元素,我想在应用程序运行期间更改其属性.

This is just because I have a large number of elements, which i would like to change the properties of during the application running.

感谢您的回答.

推荐答案

当然,如果不是正确的,请将 Me.Controls 替换为另一个控件集合.

Sure, replace Me.Controls with another control collection if that is not the right one.

标签示例:

For i = 1 To 5
  Dim lb = TryCast(GameInterface.Controls("Element" & i.ToString), Label)
  If lb IsNot Nothing Then lb.BackColor = Color.Maroon 
Next

这篇关于循环通过 vb.net 中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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