Form开发小技巧

一般情况下,按enter跳到下一控件
private void txtFindText_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
SendKeys.Send("{TAB}");
}

private void textBoxKeyUp(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)//按下的是回车
{
int tabIndex = ((Control)sender).TabIndex;//文本框的tabindex
foreach (Control cc in panel1.Controls)//轮询pannel中的所有控件
{
if (cc.TabIndex == tabIndex + 1)//找到tabindex值比这个文本框大1的那个
{
cc.Focus();//设置焦点
break;
}
}
}

}

屏蔽Tab键

Protected Overrides Function ProcessTabKey(ByVal forward As Boolean) As Boolean

//屏蔽Tab键,建议初始化时去掉按钮、菜单等的快捷键

protected override bool ProcessTabKey(bool forward) { return false; }

posted @ 2014-12-26 10:16  任锋  阅读(181)  评论(0编辑  收藏  举报