protected override bool ProcessCmdKey(ref Message msg, Keys keydata)
{
if (keydata == Keys.Enter &&
(
(
!(ActiveControl is System.Windows.Forms.TextBox) ||
!((System.Windows.Forms.TextBox)ActiveControl).AcceptsReturn)
)
&& !(ActiveControl is System.Windows.Forms.Button)
)
{
SendKeys.SendWait("{tab}");
return true;
}
if (keydata == (Keys.Enter | Keys.Shift))
{
SendKeys.SendWait("+{tab}");
return true;
}
return base.ProcessCmdKey(ref msg, keydata);
}
if (keydata == Keys.Enter &&
(
(
!(ActiveControl is System.Windows.Forms.TextBox) ||
!((System.Windows.Forms.TextBox)ActiveControl).AcceptsReturn)
)
&& !(ActiveControl is System.Windows.Forms.Button)
)
{
SendKeys.SendWait("{tab}");
return true;
}
if (keydata == (Keys.Enter | Keys.Shift))
{
SendKeys.SendWait("+{tab}");
return true;
}
return base.ProcessCmdKey(ref msg, keydata);
}
本文介绍了一个自定义事件处理过程,该过程重新定义了Enter键的行为,使其在不同控件上模拟Tab键,实现焦点跳转,并支持Shift+Enter进行逆向跳转。

362

被折叠的 条评论
为什么被折叠?



