2013-08-24 25 views
0

我有一個雙贏形式,其中形成的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 
+0

這意味着使用Keys.Delete是一個非常糟糕的選擇。選擇一把鑰匙,任何鑰匙,而不是用戶正常使用窗戶時可能使用的鑰匙。 –

+0

@HansPassant謝謝你,先生 –

回答

0

我試圖檢查myForm.ActiveControl.Name所有textbox.name控制其財產是否控制當前光標與否以及爲我工作。這裏是我使用的代碼

If e.KeyCode = Keys.Delete Then 

    If txtTIN.Name = myForm.ActiveControl.Name Or txtCustomerPhone.Name = myForm.ActiveControl.Name Or txtCustomerMobileno.Name = myForm.ActiveControl.Name Or txtCustomerEmail.Name = myForm.ActiveControl.Name Or txtCustomerAddress.Name = myForm.ActiveControl.Name Or txtCustomerName.Name = myForm.ActiveControl.Name Or txtCustomerAliasname.Name = myForm.ActiveControl.Name Or txtacgroup.Name = myForm.ActiveControl.Name Or txtcustomerOPAmount.Name = myForm.ActiveControl.Name Then 
     Exit Sub 
    Else 
     deletionprocess(txtTIN, txtCustomerPhone, txtCustomerMobileno, txtCustomerEmail, txtCustomerAddress, btnCustomerSave, txtCustomerName, txtCustomerAliasname, txtacgroup, txtcustomerOPAmount, UC_autoCompleteComboBox1, errorProvider1) 
    End If 

End If