自动设置 TabStop 值
好长时间没上来了,发个小技巧,根据控件的位置自动调整 TabStop 值,免得一个一个的设置麻烦。
1 public void AutoTabStop()
2 {
3 AutoTabStop(this);
4 }
5
6 private static void AutoTabStop(Control container)
7 {
8 foreach (Control ctrl in container.Controls)
9 {
10 if (ctrl.TabStop)
11 {
12 var y = ctrl.Top;
13 var x = ctrl.Left;
14
15 ctrl.TabIndex = y * 10 + x/100;
16 }
17
18 AutoTabStop(ctrl);
19 }
20 }
2 {
3 AutoTabStop(this);
4 }
5
6 private static void AutoTabStop(Control container)
7 {
8 foreach (Control ctrl in container.Controls)
9 {
10 if (ctrl.TabStop)
11 {
12 var y = ctrl.Top;
13 var x = ctrl.Left;
14
15 ctrl.TabIndex = y * 10 + x/100;
16 }
17
18 AutoTabStop(ctrl);
19 }
20 }
21
浙公网安备 33010602011771号