在标签页之间切换时,Winform tabcontrol意外焦点更改 [英] Winform tabcontrol unexpected focus change upon switching between tab pages

查看:613
本文介绍了在标签页之间切换时,Winform tabcontrol意外焦点更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我有一个tabcontrol,我在标签页下托管表格。窗体上有控件,如按钮和文本框。



让我们假设在标签控件中打开了2个标签页。

假设tab-page-1中的表单上有4个控件,tab-page-2中的表单上有4个控件。



用户在tab-page-1而重点是Control-3。现在用户切换到tab-page-2并在控件1中输入一些输入并关注控件2.

现在,用户切换到tab-page-1。请记住,在tab-page-1上,重点是Control-3。但是,一旦切换完成,焦点将重新切换到选项卡页面1上的Control-1。

此外,如果现在你切换回tab-page-2,焦点位于control-2,焦点现在在control-1。



我想继续关注用户在选项卡之间切换时的控制权。



任何帮助和建议都被深深接受。



谢谢!



我的尝试:



我尝试处理标签控件的各种事件以及包含在LostFocus,取消选择,取消选择,选择,选择,离开,输入等内容的标签页和表单,但没有任何作用。

所有事件都会在焦点丢失后消失。



编辑frim Chill60。我给了OP解决方案,但他们不相信。碰到这个以确定是否有人有更好的想法

解决方案

窗口一次只能关注一个控件。



标签被激活和停用;在这个过程中,控制获得和失去焦点。



如果你想跟踪焦点,你需要为每个包含一个标签的标签维护一个变量引用最后一个控件(在该选项卡上)以获得焦点。



您可以通过为每个符合条件的控件设置获得焦点事件来设置此变量(在给定标签)并在控件获得焦点时设置该变量。



(你可以访问当前的主动控件(对于标签/容器)并确定当前的焦点方式)。



当(重新)激活/选择标签时,测试变量并设置焦点(如果它具有参考/控制名称)

Hello,

I have a tabcontrol on which I am hosting forms under tab pages. There are controls on the form such as button and textboxes.

Lets assume there are 2 tab pages opened in tab control.
Also lets say there are 4 controls on a form in tab-page-1 and 4 controls on form in tab-page-2.

User is at tab-page-1 and the focus is on Control-3. Now user switches to tab-page-2 and enters some inputs in control 1 and focuses on control 2.
Now, user switches to tab-page-1. Remember, on tab-page-1, focus was on Control-3. But, as soon as switching is done, focus re-shifts to Control-1 on tab-page-1.
Also, if now you switch back to tab-page-2 where focus was at control-2, the focus is now at control-1.

I want to remain the focus at control where user left while switching between tabs.

Any helps and suggestion is deeply accepted.

Thank you!

What I have tried:

I tried handling various events of tab-control as well as tab-pages and form contained within such as LostFocus, Deselecting, Deselected, Selecting, Selected, Leave, Enter and more but none works.
All events fire post focus lost.

EDIT frim Chill60. I've given the OP the solution but they're not convinced. Bumping this to see if anyone has a better idea

解决方案

A "window" can only "focus" on one control at a time.

Tabs gets "activated" and "deactivated"; and in the process, controls gain and lose focus.

If you want to "track" focus, you need to maintain a "variable" for each tab that contains a reference to the last control (on that tab) to have focus.

You can set this variable by having a "got focus" event for each eligible control (on a given tab) and setting that variable when a control gains focus.

(You "may" also have access on the current "active control" (for the tab / container) and determine current focus that way).

When the Tab is (re)activated / selected, test the variable and set focus if it has a reference / control name.


这篇关于在标签页之间切换时,Winform tabcontrol意外焦点更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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