在表单中,我需要检查文本框详细信息,所以我使用Validated方法。我还有一个按钮来保存表单详细信息。按钮绑定F10。 文本框验证方法
Private Sub txtReportCD_Validated(sender As Object, e As EventArgs) Handles txtReportCD.Validated
If txtReportCD.Text <> String.Empty Then
cboReportName.Value = txtReportCD.Text.Trim
Else
CommonMsg.showMsg("the CD not be empty")
End If
End Sub
表单keydown
Private Sub form_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
If e.Alt AndAlso e.Control AndAlso e.Shift Then
Exit Sub
End If
Select Case e.KeyCode
'save data
Case Keys.F10
ClickButton(Me.btnSaveData, e)
e.Handled = True
End Select
End Sub
ClickButton方法
Private Sub ClickButton(ByVal btn As ButtonKdcCtrl, e As KeyEventArgs)
e.Handled = True
If e.Alt OrElse e.Control OrElse e.Shift Then
Exit Sub
End If
If btn.Enabled Then
btn.PerformClick()
End If
End Sub
btnSaveData方法
Private Sub btnSaveData_Click(sender As Object, e As EventArgs) Handles btnSaveData.Click
CommonMsg.showMsg("begin save data")
'do save form data
End Sub
当焦点在txtReportCD中时,我按F10键。表单首先执行[btn.PerformClick],然后执行[txtReportCD_Validated] 两次,最后执行[btnSaveData_Click]。
但是当焦点在txtReportCD中时,我点击btnSavaData按钮。 表单首先执行[txtReportCD_Validated] 一次而不执行[btnSaveData_Click]。
我该怎么做,当我按F10时,表单执行[txtReportCD_Validated] 一次 并且[btnSaveData_Click]不能被调用
PS:txtReportCD文本始终为空。