Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Cambiar la tecla TAB por la tecla ENTER al pasar de controles (https://www.clubdelphi.com/foros/showthread.php?t=80554)

dec 30-06-2006 13:43:03

Cambiar la tecla TAB por la tecla ENTER al pasar de controles
 
Cambiar la tecla Tab por Enter

Primer método

En el Form principal del programa en el evento OnCreate ponemos el siguiente código:

Código Delphi [-]
Application.OnMessage := AppMessage;

La declaración del procedure:

Código Delphi [-]
procedure AppMessage(var Msg: TMsg; var Handled: Boolean);

Y su código será el siguiente:
Código Delphi [-]
     procedure TMainForm.AppMessage(var Msg: TMsg; var Handled: Boolean);
     var
       actual: TWinControl;
     begin
       if Msg.message = WM_KEYDOWN then
          if Msg.wParam = VK_RETURN then
             begin
               actual := Screen.ActiveControl;
               if actual is TEdit then
                  Msg.wParam := VK_TAB;
             end;
     end;

Tener en cuenta que en MainForm hay que poner el nombre de nuestra form

Si estamos usando la versión 5.0 de Delphi o superior, colocaremos en el dicho form principal el objeto TApplication. Y en el evento OnProcessMessage, teclearemos el código de la función anterior.

Segundo método:

Código Delphi [-]
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    if not (ActiveControl is TDBGrid) then begin
      Key := #0;
      Perform(WM_NEXTDLGCTL, 0, 0);
    end
    else if (ActiveControl is TDBGrid) then
      with TDBGrid(ActiveControl) do
        if selectedindex < (fieldcount -1) then
          selectedindex := selectedindex +1
        else
          selectedindex := 0;
end;


La franja horaria es GMT +2. Ahora son las 02:51:27.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi