65.9K
CodeProject 正在变化。 阅读更多。
Home

Enter 键行为扩展器

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.63/5 (9投票s)

2007年10月21日

CPOL
viewsIcon

33317

downloadIcon

281

该组件用于包含大量文本框的窗体,这些文本框使用 Enter 键切换焦点。

Screenshot - top.gif

引言

这篇文章使处理会计应用程序和需要用数字填充文本框的应用程序变得容易,以便在按下 Enter 键时切换焦点。 这样做可以提高用户速度,因为 Enter 键位于数字键之后,而使用 Tab 键更加困难。

这项工作将通过以下简单的句子完成。

只需在 keyPressed 事件中编写代码即可。

private void textBox1_KeyPress(object sender, KeyPressEventArgs e) 
{ 
    if (e.KeyChar == (char)Keys.Enter ) 
    { 
        e.Handled = true; 
        Control control = GetNextControl((Control)sender, true); 

        if (control!= null && control.CanFocus) 
        control.Focus(); 
    } 
} 

该组件可帮助您避免编写重复且乏味的 代码。

Using the Code

FocusProvider 添加到工具箱,然后拖放。 现在,如果您单击每个 TextBoxBase ComboBox,您将能够使用合适的值设置它们的 EnterPressed 属性。

Screenshot - FocusProvider.gif

这看起来不太理想,但如果有许多文本框,它会更合适。

感谢

感谢 Homa 翻译本文。

Screenshot - poem.gif
© . All rights reserved.