我有以下代码:
For Each t As TabPage In Me.TabControl1.TabPages
For Each p As Panel In t.Controls
Dim sText As String = p.Name
If modStrings.Has(sText, u) Then
m_PrevPanel = p
p.Parent = Me.pnlMain
Return
End If
Next
Next
但有时在排队
For Each p as Panel in t.Controls
我得到了错误
“SystemWindows.Forms.Button 类型的对象无法转换为 System.Windows.Forms.Panel”。
我不明白为什么它会尝试在“p as Panel”枚举中包含一个按钮。 有人看到这里可能出了什么问题吗?
最佳答案
因为您在 TabPage 控件集合上有一个按钮。
尝试过滤它:
For Each p As Panel In t.Controls.OfType(Of Panel)()
Next
关于VB.NET For each 枚举不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21606730/