vb.net中如何将多个控件事件引用同一方法(不同控件事件引用方法的参数不同)统一写在同一事件中?
如(TextChanged(文本框控件)是一个带参数的的方法):PrivateSubTextBox1_TextChanged(senderAsObject,eAsEven...
如(TextChanged(文本框控件)是一个带参数的的方法):
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
TextChanged(TextBox1)
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
TextChanged(TextBox2)
End Sub
两个事件都是调用TextChanged(文本框控件)方法,但参数分别是TextBox1和TextBox2,如何将这两个事件合并起来写 展开
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
TextChanged(TextBox1)
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
TextChanged(TextBox2)
End Sub
两个事件都是调用TextChanged(文本框控件)方法,但参数分别是TextBox1和TextBox2,如何将这两个事件合并起来写 展开
1个回答
展开全部
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged,TextBox2.TextChanged
Try
If CType(sender,TextBox1).Tag = "0" Then
'TextBox1.textChanged更改
ElseIf CType(sender, Button).Tag = "1" Then
'TextBox2.TextChanged更改
End If
Catch ex As Exception
MsgBox("错误" & ex.Message)
End Try
End Sub
'先把TextBox1.Tag设为0;先把TextBox2.Tag设为1(也可以把其它的属性来示别)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询