如何在用户控件中设置控件的焦点,而不是其默认焦点 [英] How to set the focus for a control in user control instead of its default focus

查看:69
本文介绍了如何在用户控件中设置控件的焦点,而不是其默认焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在表单中,我正在使用用户控件和几个文本框.
用户控件具有2个链接标签和用户控件中控件的扩展选项卡序列(Link1,Link2,Spread).
加载表单时,最初的焦点应在Spread的第一个单元格上.
制表符序列应散布,Textbox1,textbo2,textbox3,link1,link2.

但是,最初的重点是Link1,而不是传播.然后在选项卡上,焦点导航到Link2,Spread,textbox1,textbox2,textbox3.
如何将初始焦点设置为Spread?

我们可以使用ActiveControl还是Focus?
我正在尝试ActiveControl,但不确定是否正确.
例如:
this.UserControl1.ActiveControl = this.UserControl1.Spread;

预先感谢您.

In a Form I am using a user control and few textboxes.
User control has 2 link labels and a spread Tab Sequence for Controls in User Control(Link1,Link2,Spread).
When the form loads the initial focus should be on first cell of the Spread.
Tab sequence should be spread,Textbox1,textbo2,textbox3,link1,link2.

But The inital focus is on Link1 instead of focusing on spread. Then on tabbing the focus navigates to Link2,Spread,textbox1,textbox2,textbox3.
How to set the initail focus to Spread?

Can we use ActiveControl or Focus?
I am trying ActiveControl but not sure whether it is correct way.
Ex:
this.UserControl1.ActiveControl = this.UserControl1.Spread;

Thank u in advance.

推荐答案

1)在设计器中打开控件.
2)从菜单中选择查看...制表顺序".
3)重新排列控件的顺序,使数字从0(您要开始使用的控件)开始,并按所需的制表顺序从一个到下一个递增,但先单击第一个,然后单击第二个,依此类推.
4)再次选择查看...制表顺序",退出制表顺序更改.
5)重建控件.

布局"工具栏上还有一个按钮,可以进入/退出选项卡顺序模式.
1) Open your control in the designer.
2) Select "View...Tab Order" from the menu.
3) Re-order your controls so the the numbers run from 0 (the control you want to start with) and increase by one to the next in the tab order you want, but clicking the first one, then the second, and so on.
4) Exit the Tab order change by selecting "View...Tab Order" again.
5) Rebuild your control.

There is also a button on the "Layout" toolbar to enter / exit tab order mode.


您好,您尝试过Spread.Focus()而不是ActiveControl吗?我通常使用Focus方法,它可以正常工作:P
Hi there, have you tried Spread.Focus() rather than ActiveControl? I normally use the Focus method and it works fine :P


这篇关于如何在用户控件中设置控件的焦点,而不是其默认焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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