我对编码和VB.net很新。只是想知道是否有更好的方法来做到这一点:
If TypeOf ctl Is ComboBox Or TypeOf ctl Is TextBox Then
' code here
End If
你能做点什么:
If TypeOf ctl is ComboBox or TextBox or... then
End If
答案 0 :(得分:2)
使用选择案例陈述
Select Case ctl.GetType
Case GetType(Button), GetType(PictureBox)
.... whatever
Case GetType(Label)
.... whatever
End Select
替代答案
使用快速数组也可以。
If {GetType(Button), GetType(PictureBox)}.Contains(ctl.GetType) Then