我有一個雙贏形式,其中形成的KeyPreview設置「真」和我寫的代碼上按形式keydown事件Delete鍵刪除數據庫的詳細信息。但是,當我嘗試清除窗體中的文本框中的內容使用刪除鍵形式keydown事件發生。我怎樣才能防止形式keydown事件發生在我按刪除清除文本框內容?形式KeyDown事件法關鍵
我用表格的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
這意味着使用Keys.Delete是一個非常糟糕的選擇。選擇一把鑰匙,任何鑰匙,而不是用戶正常使用窗戶時可能使用的鑰匙。 –
@HansPassant謝謝你,先生 –