我有一个winform,带有SplitContainer
控件。在控制范围内,我有很多文本框和带有复选框的组框。我想清除非只读文本框,并取消选中任何点击按钮上的复选框。清除分隔符容器内的文本框控件
我试图复制该代码VB.NET - Iterating through controls in a container object
Public Sub ClearRecord(ByRef container As SplitterPanel, Optional recurse As Boolean = True)
'For Each tbx As TextBox In Me.Controls.OfType(Of TextBox)()
' If Not tbx.ReadOnly Then
' tbx.Text = String.Empty
' tbx.BackColor = SystemColors.Window
' End If
'Next
'For Each chkbx As CheckBox In Me.Controls.OfType(Of CheckBox)()
' chkbx.Checked = False
'Next
Dim cntrl As Control
For Each cntrl In container.Controls
If (cntrl.GetType() Is GetType(TextBox)) Then
Dim txt As TextBox = CType(cntrl, TextBox)
If txt.ReadOnly = False Then
txt.Text = String.Empty
End If
End If
If (cntrl.GetType() Is GetType(CheckBox)) Then
Dim chk As CheckBox = CType(cntrl, CheckBox)
chk.Checked = False
End If
Next
If recurse = True Then
If (cntrl.GetType() Is GetType(GroupBox)) Then
Dim grpbx As GroupBox = CType(cntrl, GroupBox)
ClearRecord(grpbx, recurse)
End If
End If
Me.lblInvalid.Visible = False
Me.lblAddrInv.Visible = False
Me.lblZipInv.Visible = False
Me.lblInvFZ.Visible = False
Me.lblInvBFE.Visible = False
Me.lblInvalidDepth.Visible = False
End Sub
要调用子:
Private Sub Clear_Click(sender As Object, e As EventArgs) Handles Clear.Click
ClearRecord(Me.CntrLOMC.Panel1, True)
End Sub
但得到的错误:
Value of type 'System.Windows.Forms.GroupBox' cannot be converted to 'System.Windows.Forms.SplitterPanel'.
我也看着这些解决方案无回答:
Looping through Controls in VB.NET
VB.NET Loop through controls in a panel skips controls
Looping through Controls in VB.NET
Clearing many textbox controls in vb.net at once
我敢肯定,这是一个很小的细节我错过,任何人都可以找到适合我?
就像一个魅力。谢谢! – alybaba726