2016-11-29 13 views
0

私はログインフォームを持っています。 txtUserNameテキストボックスのKeyUp場合には、これを持ってテキストボックス上のシステム警告音キーアップイベントC#

private void txtUserID_KeyUp(object sender, KeyEventArgs e) 
    { 
     if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) 
     { 
      //Next control when Press Enter key 
      SelectNextControl((Control)sender, true, true, true, true); 
     } 
    } 

しかし、毎回私はEnter Keyを押すと、フォーカスが次のcontolに行くと、システム警告音を生み出します。

これを避けるにはどうすればよいですか?これには何が間違っていますか?

+0

あなたは何を達成しようとしましたか?あなたが直面している間違ったことは何ですか? –

+0

['' 'e.SuppressKeyPress = true;' '' SelectNextControlの後に ... – meganaut

+0

ユーザーがユーザー名を入力した後にEnterキーを押すと、次の 'txtPassword'Controlにフォーカスが移ります。システムサウンドと一緒に。私はそのシステムサウンドを防ぎたい。 – Alons

答えて

1

コードの横にあるEnterキーを押すと、デフォルトのイベントも発生します。あなたの方法に、e.Handled = trueを追加 :

private void txtUserID_KeyUp(object sender, KeyEventArgs e) 
    { 
     if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) 
     { 
      //Next control when Press Enter key 
      SelectNextControl((Control)sender, true, true, true, true); 
      e.Handled = true 
     } 
    } 

これは、そのイベントが処理されるように指示します。

+0

ありがとうございます。 – Alons

関連する問題