[英]How to make Enter Key as Default key for Tab Changing for all the textbox in a Window Form C#?
I am using c# window form application. 我正在使用C#窗口表单应用程序。 I have already tried many example on the internet for this query but nothing works for me.
我已经在互联网上尝试过很多查询示例,但对我来说却没有用。 I just want to replace the action of Enter key with Tab key on a Window Forms.
我只想用Window窗体上的Tab键替换Enter键的动作。 I don't want to apply keydown or up event on one by one on my textbox.
我不想在我的文本框中一一应用keydown或up事件。 I just want a single event which I can apply on my window form.
我只想要一个可以在我的窗口表单上应用的事件。
Thanks. 谢谢。
It works fine now I used these code of lines on form keyup event, and set the KeyPreview property True. 现在,我在表单keyup事件上使用了以下行代码,并将KeyPreview属性设置为True,效果很好。
if (e.KeyData == System.Windows.Forms.Keys.Enter)
{
SendKeys.Send("{TAB}");
}
Create your own custom TextBox
: 创建自己的自定义
TextBox
:
public class MyTextBox : TextBox
{
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Parent.SelectNextControl(this, true, true, true, true);
e.Handled = true;
e.SuppressKeyPress = true; // suppress Ding sound
}
base.OnKeyDown(e);
}
}
Compile the code. 编译代码。 This component will appear in the toolbar.
该组件将出现在工具栏中。 Use it instead of the regular textboxes.
使用它而不是常规文本框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.