根据:http://www.codeproject.com/Tips/737799/IntelliSense-TextBox-in-Csharp
为什么“输入”键在“句点”键不起作用时有效?
//text box key press event
txtControl.KeyPress += (s, kpeArgs) =>
{
if ((kpeArgs.KeyChar == (char)Keys.Enter) || (kpeArgs.KeyChar == (char)Keys.OemPeriod))
{
if (lstControl.Visible == true)
{
lstControl.Focus();
}
kpeArgs.Handled = true;
}
}
//listbox keyup event
lstControl.KeyUp += (s, kueArgs) =>
{
if ((kueArgs.KeyCode == Keys.Enter) || (kueArgs.KeyCode == Keys.OemPeriod))
{
string StrLS = GetLastString(txtControl.Text);
int LIOLS = txtControl.Text.LastIndexOf(StrLS);
string TempStr = txtControl.Text.Remove(LIOLS);
txtControl.Text = TempStr + ((ListBox)s).SelectedItem.ToString();
txtControl.Select(txtControl.Text.Length, 0);
txtControl.Focus();
lstControl.Hide();
}
}
我是一个学习乐趣的初学者。所以尽量不要给出太复杂或太详细的答案,好吗? :)
答案 0 :(得分:0)
改变这个:
kpeArgs.KeyChar == (char)Keys.OemPeriod)
到此:
kpeArgs.KeyChar == '.'
Keys.OemPeriod不是'。',但' 3/4'或0xBE或190.我在美国键盘上看不到它。