"pressing" the TButtonedEdit button using the keyboard

I was just about to replace the TEdit + TButton combination with one TButtonedEdit element, but when I tried to test it, I did not find a way to "press" (on the right) the button using the keyboard.

I tried Alt + Enter, Alt + Down, Alt + Right, the same keys with Ctrl and several keyboard shortcuts, but none of them worked. VCL sources also did not shed light on this problem (but, unfortunately, "professional programmers do not look at VCL sources").

Did I miss something?

This is with Delphi 2010 in the Windows XP window, the TButtonedEdit component was introduced in Delphi 2009 IIRC.

Note. I accepted the answer of Andreas Reggrand because he answers the question. But I also added my own answer for the benefit of those who may be interested in what I really implemented.

+4
source share
3 answers

No, there is no such key combination, partly (possibly) due to the ambiguity in which the button (left or right button) should be executed from the keyboard.

I always do it like this:

procedure TForm1.ButtonedEdit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (Key = VK_RETURN) and (ssCtrl in Shift) then ButtonedEdit1RightButtonClick(Sender); end; 

The Ctrl + Enter combination is very natural if the button displays a modal dialog (which helps the user fill out the editing window) or something like that. If instead a procedure is performed in which the editing text is used as an argument (for example, an address bar or a search field), then the introduction is more suitable. If the button is a cleanup button (which clears the edit window), then Escape may be the best shortcut or, possibly, the absence of a shortcut (and then itโ€™s good that the default shortcut is missing).

The fact that a suitable shortcut depends on the situation also suggests that, in my opinion, there should not be a default shortcut.

By the way, do not forget to make TButtonedEdit DoubleBuffered , otherwise it will flicker too.

+3
source

Now I created an interposer class that looks like this:

 interface {...} type TdzButtonedEdit = class(TButtonedEdit) protected procedure KeyDown(var _Key: Word; _Shift: TShiftState); override; public procedure Loaded; override; end; {...} implementation {...} { TdzButtonedEdit } procedure TdzButtonedEdit.KeyDown(var _Key: Word; _Shift: TShiftState); begin inherited; if (_Key = VK_RETURN) and (ssCtrl in _Shift) then if Assigned(OnRightButtonClick) then OnRightButtonClick(Self); end; procedure TdzButtonedEdit.Loaded; begin inherited; if RightButton.Visible and (RightButton.Hint = '') then begin RightButton.Hint := _('Ctrl+Return to ''click'' right button.'); ShowHint := true; end; end; 

which I use in form declaring:

 TButtonedEdit = class(TdzButtonedEdit) end; 

before declaring a form class.

If I ever get worried, I will make it a fully functional user component.

btw: Why did Embarcadero make TEditButton.TGlyph strict private? This is very inconvenient, because usually I would call RightButton.Glyph.Click, not OnRightButtonClick.

+2
source

Given that there is no way to pass input focus to these built-in buttons, and given that they display glyphs, how can access to the keyboard be? How can a user find it?

In the modal dialog box, you can press enter and until the focus control is a button, then the default button is pressed and the form closes. This is part of the standard UI platform. Similarly for exit and cancellation. Many other controls have standard keyboard access (lists, drop-down lists, changes, etc.).

This is not a standard control, so it would be wrong to enter default keyboard access that is greater than expected in the edit control. It is good for the designer to add access because they know what is reasonable in their form, but VCL designers have gained this right, apart from the default behavior that will apply to all instances of this control.

0
source

Source: https://habr.com/ru/post/1339533/


All Articles