C#: NoSoundTextBox 按下 Enter 鍵不會亂叫的 TextBox

  • 54882
  • 0
  • C#
  • 2008-03-23

C#: NoSoundTextBox 按下 Enter 鍵不會亂叫的 TextBox

建立一個 ClassLibrary 取名 NoSoundTextBox 填入以下程式碼,再原專案引用 NoSoundTextBox.dll。在 ToolBox 拉 NoSoundTextBox 取代 TextBox 控制項。在該控制項上,按 Enter 相當於按下 Tab 且無聲。

  1. using System.Windows.Forms;
  2. namespace NoSoundTextBox
  3. {
  4. public class NoSoundTextBox : TextBox
  5. {
  6. protected override bool ProcessDialogKey(Keys KeyCode)
  7. {
  8. if (KeyCode == Keys.Enter )
  9. {
  10. SendKeys.Send ( "{TAB}" );
  11. return true;
  12. }
  13. return base.ProcessDialogKey (KeyCode);
  14. }
  15. }
  16. }