C# 组合键 判断,文本框不接受纯回车enter
//TextBox 必须是多行文本框 private void Txt_Billcode_KeyDown(object sender, KeyEventArgs e) { if (e.Control && e.KeyCode == Keys.Enter) //当按下Ctrl和Enter 输入回车 { e.SuppressKeyPress = false; e.Handled = false; return; } else if (e.KeyCode == Keys.Enter)//单纯按下Enter不在文本框中输入回车 { e.SuppressKeyPress = true; e.Handled = true; } }
当输入内容时 并弹框提示时, 上面的代码会失效,
if (e.Control && e.KeyCode == Keys.Enter) { Txt_Billcode.AcceptsReturn = true; e.SuppressKeyPress = false; e.Handled = false; return; } else if (e.KeyCode == Keys.Enter) { Txt_Billcode.AcceptsReturn = false; Txt_Billcode.Enabled = false; string strBillcode = Txt_Billcode.Text; if (true) { MessageBox.Show(this, "提示成功"); } else { MessageBox.Show(this, "提示失败!"); } e.SuppressKeyPress = true; e.Handled = true; Txt_Billcode.Enabled = true; Txt_Billcode.Text = strBillcode; }