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(); } }
C#:设置焦点在最小的TabIndex控件上
时间: 2024-10-05 16:55:15