如何控制面板内TextBox的焦点顺序? [英] How do I control the focus order for TextBoxes inside a panel?

查看:123
本文介绍了如何控制面板内TextBox的焦点顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含许多文本框的表单.我需要一组内的一些文本框,以及另一组内的其他文本框.按组,我只需要一种使这些TextBox看起来相互归属的方法.

I have a Form with many TextBoxes. I need some TextBoxes inside one group, and other text boxes inside another group. By group, I just need a way to make these TextBoxes appear to belong with each other.

我制作了两个面板,并在其中添加了文本框.然后,我在这些面板周围放置了边框.

I made two Panels and added the TextBoxes to them. Then, I placed a border around these Panels.

但是,我的问题是,当我按下 Tab 时,焦点不会移到下一个TextBox,而是以随机的顺序 转到另一个TextBox..有时下一个TextBox位于第一个面板内,而其他时候则位于第二个面板内.如何控制焦点顺序?

However, my problem is that when I press Tab, the focus doesn't go to the next TextBox, but rather it goes in a random order to another TextBox. Sometimes the next TextBox is inside the first Panel, other times it is in the second Panel. How can I control the focus order?

这是一张说明我的观点的图片:

This is an image to illustrate my point:

推荐答案

就像其他人所说的那样,使用 TabIndex 属性指示跳动顺序,并使用 TabStop 属性确定控件是否可以完全制表.

As others have said, use the TabIndex property to indicate the tabbing order, and the TabStop property to determine whether or not the control can be tabbed to at all.

但是,设计师可以采用一种更简单的方法来执行此操作.在设计器中查看表单时,请确保已选择表单(而不是表单上的控件)(您可以通过在表单周围的空白处单击一次来执行此操作),然后选择 View-> Tab键 .

However, there is a much simpler way to do this from the designer. When looking at your form in the designer, make sure your form is selected (and not a control on the form) (you can do this by clicking once in the whitespace around the form), and then choose View -> Tab Order.

在选项卡顺序设计器处于活动状态时,您将看到每个控件的 TabIndex .按您希望能够通过它们进行制表的顺序单击它们.分配它们后, TabIndex 工具提示将从蓝色变为白色.完成后,再次选择 视图->制表顺序 ,即可返回正常的设计器状态.

With the tab order designer active, you will see the TabIndexes of every control. Click them in the order you would like to be able to tab through them. The TabIndex tooltips will change from blue to white as you assign them. When you are done, choose View -> Tab Order again to return to the normal designer state.

要提及的另一件事是建议尽可能使用 UserControl s.如果您对UI的某些部分进行精心设计的 UserControl 来重用,则可以避免使用带有数十个制表位的表格来分配,因为每个 UserControl 都有其自己的自己的内部跳位顺序,当放置在窗体上时,该跳位将自动应用,您只需设置 UserControl 本身的 TabIndex .

Another thing to mention would be to suggest using UserControls whenever possible. If you reuse parts of your UI with good design of UserControls, you can avoid having a form with dozens and dozens of tab stops to assign, since each UserControl will have its own internal tabbing order that will automatically apply when placed on a Form, and you will only have to set the TabIndex of the UserControl itself.

这篇关于如何控制面板内TextBox的焦点顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆