“按压”使用键盘的 TButtonedEdit 按钮
我正打算用一个 TButtonedEdit 控件替换 TEdit + TButton 组合,但当我尝试测试它时,我发现无法使用键盘“按下”(右)按钮。
我尝试了 Alt+Enter、Alt+Down、Alt+Right、与 Ctrl 相同的键以及更多组合键,但没有一个起作用。 VCL 源代码也没有阐明这个问题(但是嘿,“专业程序员无论如何都不看 VCL 源代码”)
我错过了什么吗?
这是 Windows XP 上的 Delphi 2010,TButtonedEdit 组件是在 Delphi 2009 IIRC 中引入的。
注意:我接受了 Andreas Rejbrand 的回答,因为它回答了问题。但我也添加了我自己的答案,以方便那些可能对我实际实现的内容感兴趣的人。
I was just about to replace a TEdit + TButton combination with one TButtonedEdit control but when I tried to test it, I found no way to "press" the (right) button using the keyboard.
I tried Alt+Enter, Alt+Down, Alt+Right, the same keys with Ctrl and a few more key combinations but none of them worked. The VCL sources did not shed any light on this issue either (but hey "professional programmers don't look at the VCL sources" anyway)
Am I missing something?
This is with Delphi 2010 on a Windows XP box, the TButtonedEdit component was introduced in Delphi 2009 IIRC.
Note: I have accepted Andreas Rejbrand's answer because it answers the question. But I have also added my own answer for the benefit of those who might be interested in what I actually implemented.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,不存在这样的键盘快捷键,部分(可能)是因为键盘快捷键应执行哪个按钮(左按钮或右按钮)不明确。
我总是这样做:
如果按钮显示模式对话框(帮助用户填充编辑框)或类似的东西,则 Ctrl+Enter 快捷键是非常自然的。如果它执行将编辑文本作为参数的过程(例如,地址栏或搜索框),则单独输入更合适。如果按钮是清除按钮(清除编辑框),那么 Escape 可能是最好的快捷方式,或者可能根本没有快捷方式(然后没有默认快捷方式是一件好事)。
我认为,合适的快捷方式取决于具体情况,这一事实也表明不应该有默认的快捷方式。
顺便说一下,不要忘记将
TButtonedEdit
设置为DoubleBuffered
,否则它会闪烁太多。No, there is no such keyboard shortcut, partly (maybe) because of the ambiguity in which button (the left or right button) the keyboard shortcut should execute.
I always do it like this:
The Ctrl+Enter shortcut is very natural if the button displays a modal dialog (which helps the user fill the edit box), or something similar. If it instead executes a procedure taking the edit text as argument (e.g., an address bar or a search box), Enter alone is more suitable. If the button is a clear button (that clears the edit box), then Escape might be the best shortcut, or possibly no shortcut at all (and then it is a good thing that there is no default shortcut).
The fact that the suitable shortcut depends on the situation also suggests that there should be no default shortcut, I think.
By the way, don't forget to make the
TButtonedEdit
DoubleBuffered
, for otherwise it will flicker way too much.我现在已经创建了一个 插入器类 看起来像这样:
声明: 在表单中使用它
我通过在表单的类声明之前
。如果我能打扰的话,我会把它变成一个完整的自定义组件。
顺便说一句:为什么 Embarcadero 将 TEditButton.TGlyph 设为严格私有?这非常不方便,因为
通常我会调用 RightButton.Glyph.Click 而不是 OnRightButtonClick。
I have now created an interposer class that looks like this:
which I use in the form by declaring:
before the form's class declaration.
If I can ever be bothered I'll make it a full blown custom component.
btw: Why did Embarcadero make TEditButton.TGlyph strict private? That's very inconvenient because
normally I would have called RightButton.Glyph.Click rather than OnRightButtonClick.
鉴于无法将输入焦点传递给这些嵌入式按钮,并且它们显示字形,怎么可能有键盘访问呢?用户如何发现它?
在模态对话框中,您可以按 Enter 键,只要焦点控件不是按钮,就会按下默认按钮并关闭窗体。这是平台 UI 标准的一部分。对于转义和取消也是如此。许多其他控件具有标准键盘访问(列表、下拉菜单、编辑等)。
这不是标准控件,因此强加一些超出编辑控件预期的默认键盘访问权限是错误的。设计者添加访问权限是很好的,因为他们知道表单上什么是合理的,但是 VCL 设计者通过不包括适用于该控件的每个实例的默认行为来做到这一点。
Given that there is no way to pass the input focus to these embedded buttons, and given that they display glyphs, how could there be keyboard access? How would the user discover it?
On a modal dialog you can press enter and so long as the focus control is not a button, then the default button is pressed and the form closes. That is part of the platform UI standard. Similarly for escape and cancel. Many other controls have standard keyboard access (lists, drop downs, edits etc.)
This is not a standard control and so it would be wrong to impose some default keyboard access beyond what is expected in an edit control. It's fine for the designer to add access because they know what is reasonable on their form, but the VCL designers got it right by not including a default behaviour that would apply to every instance of this control..