Board index » delphi » TButton: Key doen don't move

TButton: Key doen don't move

Hi,

I am having a little problem, I need to have keep the focus on a
TButton, even if the user presses the key arrow down (VK_DOWN), and I
don't how to do it, because I have tried to do it with the
Form.KeyPreview in true and in the event OnKeyDown, but it doesn't take
it with TButtons, with TEdits works OK.  But with TButtons the focus
changes to the next control if the user presses the key arrow down.

Any idea ??

Thank you,

Rocio

 

Re:TButton: Key doen don't move


Quote
> I am having a little problem, I need to have keep the focus on a
> TButton, even if the user presses the key arrow down (VK_DOWN), and I
> don't how to do it, because I have tried to do it with the
> Form.KeyPreview in true and in the event OnKeyDown, but it doesn't take
> it with TButtons, with TEdits works OK.  But with TButtons the focus
> changes to the next control if the user presses the key arrow down.

What you want to do is a clear deviation from the standard Windows UI
behaviour and will tend to confuse your users. But you can do it: add a
handler for the CM_DIALOGKEY message to your form.

    { Private declarations }
    Procedure CMDialogKey(Var Msg: TWMKey); message CM_DIALOGKEY;

Procedure TForm1.CMDialogKey(Var Msg: TWMKEY);
Begin
  If ActiveControl Is TButton Then
    If Msg.Charcode = VK_DOWN Then Begin
      // swallow key
      Msg.Result := 1;
      Exit;
    End;

  inherited;
End;

Quote

> Any idea ??

> Thank you,

> Rocio

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Re:TButton: Key doen don't move


Hi,

Thank you for the asnwer it works OK, but now, my client wants to do a
component with this procedure, but if he creates a component from TButton a
write this procedure in the private section, it only reacts to ENTER and
ESCAPE keys, why ??

Thank you,

Rocio

Quote
Peter Below (TeamB) wrote:
> > I am having a little problem, I need to have keep the focus on a
> > TButton, even if the user presses the key arrow down (VK_DOWN), and I
> > don't how to do it, because I have tried to do it with the
> > Form.KeyPreview in true and in the event OnKeyDown, but it doesn't take
> > it with TButtons, with TEdits works OK.  But with TButtons the focus
> > changes to the next control if the user presses the key arrow down.

> What you want to do is a clear deviation from the standard Windows UI
> behaviour and will tend to confuse your users. But you can do it: add a
> handler for the CM_DIALOGKEY message to your form.

>     { Private declarations }
>     Procedure CMDialogKey(Var Msg: TWMKey); message CM_DIALOGKEY;

> Procedure TForm1.CMDialogKey(Var Msg: TWMKEY);
> Begin
>   If ActiveControl Is TButton Then
>     If Msg.Charcode = VK_DOWN Then Begin
>       // swallow key
>       Msg.Result := 1;
>       Exit;
>     End;

>   inherited;
> End;

> > Any idea ??

> > Thank you,

> > Rocio

> Peter Below (TeamB)  100113.1...@compuserve.com)
> No e-mail responses, please, unless explicitly requested!

Re:TButton: Key doen don't move


Quote
In article <381860D4.62985...@colomsat.net.co>, Rocio Snchez wrote:
> Thank you for the asnwer it works OK, but now, my client wants to do a
> component with this procedure, but if he creates a component from TButton a
> write this procedure in the private section, it only reacts to ENTER and
> ESCAPE keys, why ??

A button will, by default, never get any arrow key messages. But you can tell
Windows that you want them: add a handler for the WM_GETDLGCODE message to
the new button class, have it first call the inherited handler and then do

  msg.result := msg.result or DLGC_WANTARROWS;

That should be all that is required. The mere fact that the button now
requests the arrow keys will prevent the form from seeing a CM_DIALOGKEY
message for them. The button will now get WM_KEYDOWN/WM_KEYUP messages for
the arrow keys but can simply ignore them.  

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Other Threads