您的位置:首页 > 编程语言 > C#

C#中回车键事件写法

2008-08-14 09:57 155 查看
C#中回车键事件写法

1.private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)

{

if(e.KeyValue==13)

{

MessageBox.Show("你摁下了回车");

}

}

2.public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

this.textBox1.KeyDown += new KeyEventHandler(textBox1_KeyDown);

this.button1.Click += new EventHandler(btnOK_Click);

}

void button1_Click(object sender, EventArgs e) { }

void textBox1_KeyDown(object sender, KeyEventArgs e)

{

if (e.KeyCode == Keys.Enter)

{

this.button1_Click(button1, null); //在TextBox按Enter键就执行button1的单击事件

//如果你要用引发的话要用到api

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: