0

我在表单上有一些控件,不想手动使用 , 等将这些值设置为或所有String.Empty默认值 。TextBoxesDateTimePickersComboboxList

我想要一种“清理”我所有控件以获取新数据的方法。

4

2 回答 2

0

我建议遍历您要重置的任何类型的所有控件。例如:

For Each tb In myForm.Controls.OfType(Of TextBox)
    tb.Text = String.Empty
Next tb

For Each cb In myForm.Controls.OfType(Of CheckBox)
    ' Clear out your checkboxes here
Next cb

ETC...

于 2013-06-26T18:16:13.597 回答
0

可能是这样的

    'this loop will get all the controls on the form
    'no matter what the level of container nesting

    Dim ctrl As Control = Me.GetNextControl(Me, True)
    Do Until ctrl Is Nothing
        'set defaults based on type
        Select Case True
            Case TypeOf ctrl Is TextBox
                Stop 'set defaults
            Case TypeOf ctrl Is Label
                Stop 'set defaults
            Case TypeOf ctrl Is Button
                Stop 'set defaults
        End Select
        ctrl = Me.GetNextControl(ctrl, True)
    Loop
于 2013-06-26T18:26:42.120 回答