ComboBox1_KeyDown事件,回车到底是啥子?????
private void toolStripComboBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Navigate(toolStripComboBox1.Text);
}
//MessageBox.Show(e.KeyCode.ToString());
}
当我按下回车时,响应Navigate,但老是有砰的响声,用Message Show了一下,按回车显示Return,
改为
Keys.Return
结果如故,咋了??
Navigate代码:
public void Navigate(string address)
{
if (string.IsNullOrEmpty(address)) return;
if (address.Equals( "about:blank ")) return;
if (!address.StartsWith( "http:// ")) address = "http:// " + address;
try
{
webBrowser1.Navigate(new Uri(address));
}
catch(System.UriFormatException)
{
return;
}
}
先谢谢了.....
------解决方案--------------------//这样,通过KeyPress处理,当碰见Enter和Esc的时候截获掉
private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = (e.KeyChar == (char)27) || (e.KeyChar == (char)13);
}
------解决方案--------------------private void toolStripComboBox1_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyValue == 13)//13是回车的AscII码
{
Navigate(toolStripComboBox1.Text);
}
}