MS Access 选项卡控制:焦点错误

发布于 2024-10-03 02:58:44 字数 409 浏览 2 评论 0原文

我有一个具有不同页面的选项卡控件。当使用此选项卡控件启动表单时,选项卡会丢失,并且内页会获得所有屏幕焦点。选项卡控件用于导航,因此用户会迷失方向。

有没有什么方法可以让选项卡在屏幕上可见,而无需将屏幕调整得更小?

期望结果:

+--------------------+
| Tab1 | Tab2 | Tab3 |
+--------------------+
| Name: ______       |

实际屏幕:

                        ^
+--------------------+ |_|
| Name: ______       | | |

I have a tab control with different pages. When starting up the form with this tab control the tabs get lost and the inner page gets all the screen focus. The tab control is used for navigation so the user will get lost this way.

Is there any way to let the tabs be visible on the screen without just resizing the screen to be smaller?

Desired result:

+--------------------+
| Tab1 | Tab2 | Tab3 |
+--------------------+
| Name: ______       |

Actual screen:

                        ^
+--------------------+ |_|
| Name: ______       | | |

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

可可 2024-10-10 02:58:44

减小选项卡控件的大小是可行的(正如您自己发现的那样),但是还有一种替代解决方法:

  1. 添加一个命令按钮并将其与选项卡控件的左上角对齐
  2. 将其 Tab Stop 属性设置为“否”(在“其他”中) ' 命令按钮属性表的选项卡)
  3. 发送到底层将命令按钮放在选项卡控件后面
  4. 在窗体的 OnOpenOnLoad 事件中,调用 .SetFocus命令按钮上的 方法
  5. 使用 SendKeys(我知道,我知道...)切换到选项卡控件

示例代码:

Private Sub Form_Open(Cancel As Integer)
    Me.HiddenCommandButton.SetFocus
    SendKeys "{Tab}"
End Sub

上述步骤的说明:

  1. 这允许您向 Access 指令它应该在屏幕上排列表单的位置。
  2. 将命令按钮的制表位设置为“否”可防止用户意外按制表键并导致混乱。
  3. 将按钮放在后面可以将其隐藏起来,防止用户点击鼠标。
  4. 在窗体启动时将焦点设置到命令按钮是必要的,因为我们在步骤 2 中关闭了 Tab Stop 属性。
  5. 使用 SendKeys(始终是最后的手段,并且有充分的理由)来模拟 Tab 按下,为 Tab 提供了“键盘焦点”控件(只要选项卡控件是该控件所属表单的任何部分的选项卡顺序中的第一个控件)。

杂项注释:应提问者的要求,我在答案中添加了一些评论:

@mwolfe:关于 SendKeys 的最后一点说明...它在 UAC 下爆炸了
维斯塔/Win7。如果你可以没有
键盘焦点,我想说离开
SendKeys 完全退出。如果你需要的话
你要么想添加错误
处理忽略错误(如果您
不要介意一些用户的流失
键盘焦点功能)或
绕过 SendKeys 并使用 WinAPI
直接地。卡尔·彼得森提供了
交钥匙解决方案在这里:
vb.mvps.org/samples/SendInput 我有
从未使用过它所以无法评论它
可靠性,但 Karl 是 Microsoft 的
MVP,因此他获得了一些可信度。

@Roman Glass:mwolfe02 我相信你这个方法会起作用,但是
专注对我和一些用户来说至关重要
在 Windows 7 下工作。我会
暂时放下这个问题来寻找
关于用户的反应。
不过我认为你的解决方案
值得解决。最后我有
与 WinAPI 对话。也许你可以
编辑你的答案以包含此内容
直接评论。谢谢!

对于那些将来可能找到此答案的人,请注意,仅当您需要选项卡控件接收键盘焦点时才需要执行上述步骤 5(这是原始提问者的关键要求)。如果你可以没有它生活,我建议你这样做。

更新:正如 David Fenton 在评论中指出的那样,您可以使用 Ctl + Tab/Ctl + Shift + Tab 在选项卡之间来回移动。这与大多数选项卡式界面(例如浏览器)一致,并且无需使用 SendKeys

Reducing the size of the tab control works (as you discovered yourself), however there is an alternative workaround:

  1. Add a command button and align it with the top left corner of the tab control
  2. Set its Tab Stop property to No (in the 'Other' tab of the command button property sheet)
  3. Send To Back to put the command button behind the tab control
  4. In the Form's OnOpen or OnLoad event, call the .SetFocus method on the command button
  5. Use SendKeys (I know, I know...) to tab to the Tab Control

Sample code:

Private Sub Form_Open(Cancel As Integer)
    Me.HiddenCommandButton.SetFocus
    SendKeys "{Tab}"
End Sub

Explanation of the above steps:

  1. This allows you to dictate to Access where it should line up the form on screen.
  2. Setting the Tab Stop to No for the command button prevents users from accidentally tabbing to it and causing confusion.
  3. Sending the button to the back hides it from the user and prevents it from interfering with any mouse clicking.
  4. Setting focus to the command button at form start up is necessary since we turned off the Tab Stop property in step 2.
  5. Using SendKeys (always a last resort, and for good reason) to simulate a tab press provides "keyboard focus" to the Tab Control (as long as the tab control is the first control in the tab order for whatever section of the form the control is a part of).

Miscellaneous Notes: At the asker's request I am including a couple of comments as part of the answer itself:

@mwolfe: One final note on SendKeys...it blows up under UAC in
Vista/Win7. If you can live without
the keyboard focus, I'd say leave
SendKeys out entirely. If you need it
you'll either want to add error
handling to ignore the error (if you
don't mind some of your users losing
keyboard focus functionality) or
bypass SendKeys and use the WinAPI
directly. Karl Peterson offers a
turnkey solution here:
vb.mvps.org/samples/SendInput I have
never used it so can't comment on its
reliability, but Karl is a Microsoft
MVP so he's get some credibility.

@Roman Glass: mwolfe02 I trust you in that this method will work, but the
focus is crucial for me AND some users
are working under Windows 7. I will
drop this issue for the moment to find
out about the user reactions.
Nevertheless I think your solution
deserves a solved. In the end I have
to talk with the WinAPI. Maybe you can
edit your answer to include this
comment directly. Thanks!

For those who may find this answer in the future, please take note that Step 5 above is only necessary if you need the tab control to receive keyboard focus (a critical requirement for the original asker). If you can live without it, I would suggest that you do.

UPDATE: As David Fenton points out in the comments, you can use Ctl + Tab/Ctl + Shift + Tab to move back and forth between the tabs. This is consistent with most tabbed interfaces (eg, browsers) and eliminates the need to use SendKeys.

木落 2024-10-10 02:58:44

嗯,我知道我只使用过 Tab 控件一两次 - 但在执行/加载表单时它在表单上显示时从未遇到过问题。当然,除了表单的“详细信息”部分之外,我从未在任何地方使用过它,但我会说检查一下这头野兽是否以某种方式将其“启用”或“可见”属性(如果适用)设置为“否”。当然,我可能是错的——这种情况确实发生了,当它发生时我渴望学习新的东西。 :)

Hmmm, I know I've only played with the Tab control once or twice - but never had a problem with it showing up on the form when the form is executed/loaded. Granted, I've never had it in any place except the Detail section of the form, but I'd say check to see if the beast has somehow gotten it's Enabled or Visible property (if applicable) set to No. Of course, I could be wrong - it happens, and I am eager to learn something new when it happens. :)

赏烟花じ飞满天 2024-10-10 02:58:44

我不知道我是否理解这个问题,但在评论中,您说 Access 不允许您将焦点设置到选项卡控件,但您可以将焦点设置到选项卡页:

  Me!ctlTab.Pages(N).SetFocus

...其中 N 是您想要将焦点设置到的选项卡页的索引),或 with:

  Me!pgeTabPageName.SetFocus

这两者都可以将焦点设置到选项卡页。

您说您想将焦点设置到选项卡控件,但我不明白您为什么要这样做。选项卡控件本身没有可以获得焦点的元素——只有其 Pages 集合的成员可以获得焦点。

我再次建议您由于某些其他原因而将自己逼入绝境,并且没有解决办法。因此,你必须弄清楚如何避免陷入这个无法解决的问题。我只是不太理解您对问题的解释,无法提供解决方案,但我怀疑没有办法通过不同的方法来解决问题。

I don't know that I understand the question, but in a comment, you say that Access doesn't allow you to set focus to a tab control, but you can set focus to the tab page:

  Me!ctlTab.Pages(N).SetFocus

...where N is the index of the tab page you want to set focus to), or with:

  Me!pgeTabPageName.SetFocus

Both of these work to set focus to the tab page.

You say you want to set focus to the tab control, but I can't figure out why you'd want to do that. The tab control itself has no elements that can get focus -- only the members of its Pages collection do.

Again, I would suggest that you've painted yourself into a corner for some other reason and there's no solution. Therefore, you have to figure out how to avoid getting into that insoluble problem. I simply don't understand your explanation of the problem well enough to be able to offer a solution, but I doubt there's no way to resolve the issue through a different approach.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文