最近在寫一個WINFORM 的程序,需要捕獲按鍵,用keypress 在中文情況下 捕獲的keycode一直是229
網上查了很多資料,都不能很好的解決這個問題。
最後我也只能變相的來解決了
在肯定不用中文輸入的地方 將 imeMode 設置爲 disable
在需要中文的地方用TextChanged事件來處理按鍵(杯具啊...)
//FIX 229 BUG TextBox tb = (TextBox)sender; if (tb.Text.Length>0) { string sTemp = tb.Text; int iIndex = sTemp.IndexOf('/'); if (iIndex>-1)//key multiply { //something to do tb.Text = tb.Text.Remove(iIndex, 1); } iIndex=sTemp.IndexOf('*'); if (iIndex>-1) { //something to do tb.Text = tb.Text.Remove(iIndex, 1); } }