【发布时间】:2011-03-01 21:31:26
【问题描述】:
感谢汉斯!这是下面的技巧
this.KeyPress += new KeyPressEventHandler(TabbedTextBox_KeyPress);
void TabbedTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '.')
{
e.Handled = true;
var nextControl = this.Parent.GetNextControl(this, forward: true);
nextControl.Focus();
}
}
好的,这里有更多细节。
这可行,但“。”显示在文本框控件中(不需要)
this.KeyDown += new KeyEventHandler(TabbedTextBox_KeyDown);
}
void TabbedTextBox_KeyDown(object sender, KeyEventArgs e)
{
//MessageBox.Show("Event: " + e.KeyCode.ToString());
if (e.KeyCode == Keys.Decimal || e.KeyCode == Keys.OemPeriod)
{
var nextControl = this.Parent.GetNextControl(this, forward: true);
nextControl.Focus();
}
}
当我使用此事件处理程序时,我无法绑定到 e.keycode,因为它在上下文中不存在
this.KeyPress += new KeyPressEventHandler(TabbedTextBox_KeyPress);
void TabbedTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
//MessageBox.Show("KeyPress Event: " + e.KeyChar.ToString());
if (e.KeyChar == (char)Keys.Decimal || e.KeyChar == (char)Keys.OemPeriod)
{
MessageBox.Show("KeyPress Captured: " + e.KeyChar.ToString());
}
}
我试图捕捉“。”键被按下,因为我创建了一个具有 IP 地址的表单,并且我想在“。”时自动选项卡。键被按下。当我按下“。”时,第一个消息框会显示此消息。无论是在小键盘上还是在 ALT 键上方,但从不进入 if 语句我都尝试过
if (e.KeyChar == (char)Keys.Decimal)
和
if (e.KeyChar == (char)Keys.OemPeriod)
消息框显示这个 按键事件:.
我似乎无法弄清楚正确的代码是什么...... 我一直试图从 msdn Keys Enumeration
void TabbedTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
MessageBox.Show("KeyPress Event: " + e.KeyChar.ToString());
if (e.KeyChar == (char)Keys.Decimal)
{
MessageBox.Show("KeyPress Captured: " + e.KeyChar.ToString());
}
}
谢谢 杰森
【问题讨论】: