111,113
社区成员




private void textBox_KeyDown(object sender, KeyEventArgs e)
{
keystr = "";
if (e.Control)
{
if (!keystr.Contains("Ctrl+"))
keystr += "Ctrl+";
}
keystr += e.KeyCode.ToString();
//MessageBox.Show(keystr);
textBox.Text = keystr;
textBox.Select(textBox.Text.Length, 0);//光标定位到文本最后
textBox.ScrollToCaret();//滚动到光标处
}
private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
// Initialize the flag to false.
nonNumberEntered = false;
// Determine whether the keystroke is a number from the top of the keyboard.
if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)
{
// Determine whether the keystroke is a number from the keypad.
if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
{
// Determine whether the keystroke is a backspace.
if(e.KeyCode != Keys.Back)
{
// A non-numerical keystroke was pressed.
// Set the flag to true and evaluate in KeyPress event.
nonNumberEntered = true;
}
}
}
//If shift key was pressed, it's not a number.
if (Control.ModifierKeys == Keys.Shift) {
nonNumberEntered = true;
}
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
e.Handled = false;
if (e.Modifiers.CompareTo(Keys.Control) == 0 && e.KeyCode == Keys.A)
{
MessageBox.Show("Press Ctrl+A");
}
}