首页 > 代码库 > C#:设置焦点在最小的TabIndex控件上

C#:设置焦点在最小的TabIndex控件上

private void FocusFirstTabIndex(Control container){    // init search result varialble    Control searchResult = null;    // find the control with the lowest tab index    foreach (Control control in container.Controls)    {        if (control.CanFocus && (searchResult == null || control.TabIndex < searchResult.TabIndex))        {            searchResult = control;        }    }    // check if anything searchResult    if (searchResult != null)    {        // focus found control        searchResult.Focus();    }    else    {        // focus the container        container.Focus();    }}