Delphi:TRadioButton的TabStop问题
当 TRadioButton 的 TabStop=True 时,它的行为非常奇怪。
如果您尝试使用 Tab 键在表单上的多个单选按钮之间切换焦点,则每个应用程序会话只需执行 1 次。制表是单向的,永远不会返回到第一个单选按钮。此外,当焦点移过单选按钮时,它们会自动“选中”。
可以在不创建我自己的组件的情况下修复此行为吗?
我希望标准单选按钮
- 循环切换焦点,
- 防止单选按钮在焦点进入时进行检查(我希望我的用户使用空格键检查它们)
When TRadioButton has TabStop=True, it's acting very strange.
If you will try to switch focus between many radio buttons on a form using Tab key, you would do it only 1 time per app session. The tabulation is one-way, never returning back to the first radio button. Also when the focus is moving across radio buttons, they becoming "checked" automatically.
Can this behavior be fixed without creating my own component?
I want standard radio buttons to
- switch focus cyclically
- prevent radio button from checking when the focus comes into it (I want my users to check them using Space key)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
据我所知,您正在使用现有代码,这是现实世界的限制,在这些论坛中经常被忽视。
在我看来,复选框更适合你。您可以在 OnChecked 事件中强制执行通常期望的 RadioButton 的排他性。这应该可以解决您的选项卡/焦点和选择/取消选择问题。
接收焦点后不会自动选中复选框,您的用户可以使用空格键选中/取消选中它们。
I understand that you're working with existing code, which is a real world constraint that's too often dismissed in these forums.
Sounds to me like checkboxes would suit you better. You can enforce the exclusivity normally expected of RadioButtons in the OnChecked event. That should solve your tabbing/focus and selection/deselection issues.
Checkboxes won't be checked automatically upon receiving focus, and your users can check/uncheck them with the space key.
您可以将代码放入
OnEnter
事件中以防止选中该复选框。不过,您需要以某种方式存储之前选择的
RadioButton
。创建一个新的 TMyRadioButton 组件可能会更清楚,因为这会使您的常规代码变得混乱。
You can put code in the
OnEnter
event to prevent the checkbox from selecting.You'll need to store the previously selected
RadioButton
somehow though.It probably clearer to create a new TMyRadioButton component though because this will clutter up your regular code.
我发现了一篇关于这个问题的 Craig Stuntz 的有趣文章。正如我所看到的,我需要创建自己的控件来解决它。
I have found an interesting article of Craig Stuntz about this problem. As I can see, I'll need to create my own control to solve it.
默认情况下,只有一个 RadioButon 具有属性 TabStop = True;
所有单选按钮均被视为一个控件。
当单选按钮具有焦点时,您可以使用向上和向下箭头在单选按钮之间切换。
现在,当用户选择一个选项时,他们可以按 Tab 键切换到另一个控件(无需更改单选选项)。
By default only one RadioButon has property TabStop = True;
All Radiobuttons are treated as one controll.
When radiobutton has focus you can switch beetween radiobutons using arrow up and down.
Now when user choose one option they can press tab to switch to another controll (without changing radio options).