C# 在 Windows 窗体中按 Enter 提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/625173/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 10:45:57  来源:igfitidea点击:

Submit by pressing enter in a windows form

c#winforms

提问by Avik

In order to transfer text from one textbox to another, I have created a submit button. However it would be preferable to use the functionality of the 'enter' key.

为了将文本从一个文本框传输到另一个文本框,我创建了一个提交按钮。但是,最好使用“输入”键的功能。

I am not sure but i think the ascii code is 13.Anyway how do I go about this task at hand?

我不确定,但我认为 ascii 代码是 13。无论如何,我该如何完成手头的这项任务?

采纳答案by leppie

Look at the Form.AcceptButtonproperty.

Form.AcceptButton楼盘。

回答by Brownman98

You can subscribe to the KeyUp event of the text box.

您可以订阅文本框的 KeyUp 事件。

using System.Windows.Forms;

private void txtInput_KeyUp(object sender, KeyEventArgs e)
{
    if(e.KeyCode == Keys.Enter)
        DoSomething();
}