我有一个 win 表单,其中表单 KeyPreview 设置为“true”,我编写了代码以在表单 keydown 事件中按 Delete 键时从数据库中删除详细信息。但是,当我尝试使用 Delete 键清除表单中文本框中的内容时,会发生表单 keydown 事件。如何防止在按 Delete 清除文本框内容时发生表单 keydown 事件?
我用于 Form KeyDown 的代码是
Public Sub frm_Customers_KeyDown(ByVal myForm As frm_Customers, ByVal e As System.Windows.Forms.KeyEventArgs, ByVal txtTIN As TextBox, ByVal txtCustomerPhone As TextBox, ByVal txtCustomerMobileno As TextBox, ByVal txtCustomerEmail As TextBox, ByVal txtCustomerAddress As TextBox, ByVal btnCustomerSave As Button, ByVal txtCustomerName As TextBox, ByVal txtCustomerAliasname As TextBox, ByVal txtacgroup As TextBox, ByVal txtcustomerOPAmount As TextBox, ByVal UC_autoCompleteComboBox1 As UC_autoCompleteComboBox, ByVal frm As Form, ByVal errorProvider1 As System.Windows.Forms.ErrorProvider, ByVal rbCredit As RadioButton)
If e.KeyCode = Keys.F2 Then
If btnCustomerSave.Tag = 1 Then
updateprocess(txtTIN, txtCustomerPhone, txtCustomerMobileno, txtCustomerEmail, txtCustomerAddress, btnCustomerSave, txtCustomerName, txtCustomerAliasname, txtacgroup, txtcustomerOPAmount, UC_autoCompleteComboBox1, errorProvider1, rbCredit)
Else
saveprocess(txtTIN, txtCustomerPhone, txtCustomerMobileno, txtCustomerEmail, txtCustomerAddress, btnCustomerSave, txtCustomerName, txtCustomerAliasname, txtacgroup, txtcustomerOPAmount, UC_autoCompleteComboBox1, errorProvider1, rbCredit)
End If
ElseIf e.KeyCode = Keys.Delete Then
deletionprocess(txtTIN, txtCustomerPhone, txtCustomerMobileno, txtCustomerEmail, txtCustomerAddress, btnCustomerSave, txtCustomerName, txtCustomerAliasname, txtacgroup, txtcustomerOPAmount, UC_autoCompleteComboBox1, errorProvider1)
End If
End Sub