回车键代码为什么不能用、?
if (e.KeyChar == 13){
button1_Click(null, null);
}
class Test { static void button_Click(object button, EventArgs args) { MessageBox.Show("Submitted!"); } static void Main() { Button button = new Button { Text = "Submit", Top = 40 }; button.Click += button_Click; TextBox textBox = new TextBox(); textBox.KeyPress += (s, a) => { if (a.KeyChar == 13) { button_Click(null, null); } }; Form form = new Form(); form.Controls.Add(textBox); form.Controls.Add(button); Application.Run(form); } }