我有四个textbox
的IP地址。每个textbox
都适用于每个octate。
当控件失去焦点或用户按下ENTER
时,它将检查该值是否大于255。
Private Sub txtParametersIpFirst_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtParametersIpFirst.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
'Check if Value is more than 255
End If
End Sub
Private Sub txtParametersIpFirst_LostFocus(sender As Object, e As EventArgs) Handles txtParametersIpFirst.LostFocus
'Check if Value is more than 255
End Sub
这两个事件是否结合在一起?
答案 0 :(得分:0)
答案 1 :(得分:0)
组合两个事件的最佳方法是调用方法..
Private Sub Logic()
'Check if Value is more than 255
End Sub
Private Sub txtParametersIpFirst_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtParametersIpFirst.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
Logic()
End If
End Sub
Private Sub txtParametersIpFirst_LostFocus(sender As Object, e As EventArgs) Handles txtParametersIpFirst.LostFocus
Logic()
End Sub
但是,如果您要组合两个相同的事件,例如两个不同文本框的两个Lostfocus事件,那么您只需添加句柄;
Private Sub txtText1_LostFocus(sender As Object, e As EventArgs) Handles txtText1.LostFocus, txtText2.LostFocus,
' Code similar for both textbox
' You can use the Sender param to verify who's triggering the event
End Sub