Winforms,在同一窗体中如何将用户控件的选项卡索引分开?

4

我有一个winform窗体,其中我添加了一个2行2列的表格布局面板。 我在每个单元格中添加了不同的用户控件,并为它们设置了自己的tab索引顺序。但问题是似乎tab索引与整个窗体相关联,也就是说:

UserControl1 has 4 textboxes with tab index: 0,1,2,3
UserControl2 has 4 textboxes with tab index: 0,1,2,3
UserControl3 has 4 textboxes with tab index: 0,1,2,3
UserControl4 has 4 textboxes with tab index: 0,1,2,3

当我在UserControl1文本框1中按下tab键时,它跳到了UserControl2的文本框1,而不是跳到UserControl1的文本框2。 所有的控件都是动态加载的,所以tab索引是在循环中计算的。 有没有办法告诉表单只按照用户控件的顺序来处理tab键,而不是表单的顺序?

2个回答

3

不过,如果他是在运行时生成控件的话,就不能这么说了;-) - Fabian Bigler

1
如果你无论如何都要生成用户控件,那么有什么理由不像这样设置选项卡索引呢?
UserControl1 has 4 textboxes with tab index: 0,1,2,3
UserControl2 has 4 textboxes with tab index: 4,5,6,7
UserControl3 has 4 textboxes with tab index: 8,9,10,11
UserControl4 has 4 textboxes with tab index: 12,13,14,15

另一个猜测是仅设置用户控件本身的TabIndex:
UserControl1.TabIndex = 0; 4 textboxes with tab index: 0,1,2,3
UserControl2.TabIndex = 1; 4 textboxes with tab index: 0,1,2,3
UserControl3.TabIndex = 2; 4 textboxes with tab index: 0,1,2,3
UserControl4.TabIndex = 3; 4 textboxes with tab index: 0,1,2,3

每次从开始运行的循环。 - Liran Friedman

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接