我想做一個foreach循環,檢查面板中的每個文本框,並更改BackColor,如果它的文本是什麼。我已經試過如下:對於每個文本框循環
Dim c As TextBox
For Each c In Panel1.Controls
if c.Text = "" Then
c.BackColor = Color.LightYellow
End If
Next
,但我得到的錯誤:
Unable to cast object of type System.Windows.Forms.Label to type System.windows.forms.textbox
如果面板中有非文本框控件,則需要考慮它們。 –
我該怎麼做呢? – Lift
可能重複的[無法將'System.Windows.Forms.Button'類型的對象轉換爲類型>'System.Windows.Forms.TextBox'](http://stackoverflow.com/questions/13002128/unable-to- cast-object-of-type-system-windows-forms-button-to-type-system-wi) –