更改同一表单中所有文本框的属性VB.NET
我正在寻找解决此代码的方法:更改同一表单中所有文本框的属性VB.NET,vb.net,Vb.net,我正在寻找解决此代码的方法: For Each txtbox As TextBox In Me.Controls If txtbox.GetType.ToString = "System.Windows.Form.TextBox" Then CType(txtbox, TextBox).CharacterCasing = CharacterCasing.Upper End If Next 它抛出错误: 无法将类型为“S
For Each txtbox As TextBox In Me.Controls
If txtbox.GetType.ToString = "System.Windows.Form.TextBox" Then
CType(txtbox, TextBox).CharacterCasing = CharacterCasing.Upper
End If
Next
它抛出错误:
无法将类型为“System.Windows.Forms.Button”的对象强制转换为类型为“System.Windows.Forms.TextBox” 问题在于,您正在遍历所有控件,甚至是按钮,并试图将每个控件强制转换为文本框,而文本框将抛出您在对按钮(或其他非文本框控件)执行此操作时得到的异常 试试这个:
For Each ctrl As System.Windows.Forms.Control In Me.Controls
If TypeOf ctrl Is System.Windows.Forms.TextBox Then
CType(ctrl, System.Windows.Forms.TextBox).CharacterCasing = CharacterCasing.Upper
End If
Next
问题是,您正在遍历所有控件,甚至是按钮,并尝试将每个控件强制转换为一个文本框,该文本框将抛出您在对按钮(或其他非文本框控件)执行此操作时得到的异常 试试这个:
For Each ctrl As System.Windows.Forms.Control In Me.Controls
If TypeOf ctrl Is System.Windows.Forms.TextBox Then
CType(ctrl, System.Windows.Forms.TextBox).CharacterCasing = CharacterCasing.Upper
End If
Next
问题是,您正在遍历所有控件,甚至是按钮,并尝试将每个控件强制转换为一个文本框,该文本框将抛出您在对按钮(或其他非文本框控件)执行此操作时得到的异常 试试这个:
For Each ctrl As System.Windows.Forms.Control In Me.Controls
If TypeOf ctrl Is System.Windows.Forms.TextBox Then
CType(ctrl, System.Windows.Forms.TextBox).CharacterCasing = CharacterCasing.Upper
End If
Next
问题是,您正在遍历所有控件,甚至是按钮,并尝试将每个控件强制转换为一个文本框,该文本框将抛出您在对按钮(或其他非文本框控件)执行此操作时得到的异常 试试这个:
For Each ctrl As System.Windows.Forms.Control In Me.Controls
If TypeOf ctrl Is System.Windows.Forms.TextBox Then
CType(ctrl, System.Windows.Forms.TextBox).CharacterCasing = CharacterCasing.Upper
End If
Next
创建一个textbox对象数组,无需担心强制转换。由于不检查类型,因此性能更好
For Each tb As Textbox In Me.Controls.OfType(Of Textbox)()
tb.CharacterCasing = CharacterCasing.Upper
Next
创建一个textbox对象数组,无需担心强制转换。由于不检查类型,因此性能更好
For Each tb As Textbox In Me.Controls.OfType(Of Textbox)()
tb.CharacterCasing = CharacterCasing.Upper
Next
创建一个textbox对象数组,无需担心强制转换。由于不检查类型,因此性能更好
For Each tb As Textbox In Me.Controls.OfType(Of Textbox)()
tb.CharacterCasing = CharacterCasing.Upper
Next
创建一个textbox对象数组,无需担心强制转换。由于不检查类型,因此性能更好
For Each tb As Textbox In Me.Controls.OfType(Of Textbox)()
tb.CharacterCasing = CharacterCasing.Upper
Next