【问题标题】:How to change the order controls are read in .Net?如何更改在.Net 中读取的顺序控件?
【发布时间】:2016-10-25 18:53:57
【问题描述】:

我有一个文本框非常丰富的重型面板(大约 25 个文本框),我想从中检索所有文本。

我已经使用这个循环完成了。

Dim AllItemsArray As New ArrayList
For Each txt As Control In Panel2.Controls
        If txt.GetType Is GetType(TextBox) Then
            AllItemsArray.Add(txt.Text)
        End If
Next

但是,由于某些奇怪的原因,它以完全随机的顺序读取文本框,这使得使用信息变得极其困难。 我以为文本框是按照它们的制作顺序阅读的,但到目前为止还没有这样做。

有人对我如何更改它以使其按顺序读取文本框有任何建议吗?

IE。 textbox1.text, textbox2.text ...等

而不是

textbox5.text, textbox2.text, textbox 20 ....etc

谢谢

【问题讨论】:

  • 看看this,这应该有助于您订购Controls

标签: vb.net forms textbox


【解决方案1】:

这会按 Tab 键顺序获取控件。它还获取容器中的控件,即 GroupBox。

    Dim ctrl As Control = Me.GetNextControl(ctrl, True)
    Do While ctrl IsNot Nothing
        Debug.WriteLine(ctrl.Name)

        ctrl = Me.GetNextControl(ctrl, True)
    Loop

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 2012-11-03
    • 2013-06-08
    • 1970-01-01
    相关资源
    最近更新 更多