2009-11-26 22 views
1

每當我將焦點從一個文本框更改爲另一個文本框時,它會發出惱人的警告/錯誤嘟嘟聲。更改焦點時禁用警告/錯誤嗶聲

例子:

public void textBox1_KeyPress(object sender, KeyPressEventArgs e) 
{ 
    if (e.KeyChar == (char)Keys.Return) 
     textBox2.Focus(); 
} 

每當我按輸入它改變了焦點TextBox2中,並給出了警告聲。

任何幫助禁用此將不勝感激。 謝謝。

回答

4

我想你想添加e.Handled = true到事件處理程序:

public void textBox1_KeyPress(object sender, KeyPressEventArgs e) 
{ 
    if (e.KeyChar == (char)Keys.Return) 
    { 
     textBox2.Focus(); 
     e.Handled = true; 
    } 
} 

A面節點:你應該能夠使用KeyCode代替KeyChar財產,避免了轉換:

public void textBox1_KeyPress(object sender, KeyPressEventArgs e) 
{ 
    if (e.KeyCode == Keys.Return) 
    { 
     textBox2.Focus(); 
     e.Handled = true; 
    } 
} 
+0

謝謝。 這個技巧! – elvispt 2009-11-26 23:48:47