注意2个事件用的方式是不一样的
1.
private void txtSiteCode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (this.txtSiteCode.Text.Trim() == "") { this.txtSiteCode.Focus(); } } }
2.
private void txtBarcodeCode_KeyPress(object sender, KeyPressEventArgs e) { //回车事件 if (e.KeyChar == 13) { this.InsertTxt(); } }