|
private void frmLogin_KeyPress(object sender, KeyPressEventArgs e)
{
//按回车键查找下一个可设置焦点的组件。
if (e.KeyChar == (Char)Keys.Enter)
{
this.SelectNextControl(this.ActiveControl, true, true, true, true);
e.Handled = true;
}
}
/// <summary>
/// 定位下一个输入控件,自定义函数.
/// </summary>
protected virtual void SelectNextControl(Control activeControl)
{
try
{
Control current = activeControl;
while (true)
{
current = this.GetNextControl(current, true);
if (current is GridControl)
{
GridControl grid = current as GridControl;
grid.Focus();
break;
}
//未知原因TagStop会自动设为False,MemoEdit要单独处理.
if ((current is MemoEdit) && (current.CanFocus))
{
current.Focus();
break;
}
if (current is TextBoxMaskBox)
{
TextEdit owner = ((TextBoxMaskBox)current).OwnerEdit;
if (owner != null && owner is MemoEdit) continue; //跳过文本输入框.
}
if (current != null && current.TabStop == true && current.CanFocus)
{
if (current.Parent == activeControl) continue; //避免嵌入式输入框
current.Focus();
break;
}
}
}
catch (Exception ex)
{
Msg.ShowException(ex);
}
}
|
评分
-
查看全部评分
|