回车键代码为什么不能用、?
if (e.KeyChar == 13){
button1_Click(null, null);
}
2011-10-28 15:25
2011-10-28 20:21
程序代码: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);
}
}
2011-10-29 07:26