Fórum Tab/Enter em todos Forms #227451

22/04/2004

0

Estou utilizando o seguinte código para avançar campos com o ENTER:
procedure TF_VslCli01.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
begin
Key := 0;
SendMessage(Self.Handle, Wm_NextDlgCtl,0,0);
end;
end;

Gostaria de saber se tem uma forma de implementar em todo o meu projeto ou terei que repetir esta rotina em todos os forms que eu criar?

Desde já agradeço qualquer ajuda.

Rony Lee


Ronylee

Ronylee

Responder

Posts

22/04/2004

Weverton

:arrow: Vc pode fazer de duas formas:

1 - Criar um form, implementar esse código no OnKeyPress e criar os outros forms herdando desse primeiro;
2 - Colocar um componente ApplicationEvents no form principal da aplicação e fazer o tratamento no evento OnMessage.


Responder

Gostei + 0

22/04/2004

Ronylee

Weverton acho que a segunda opção seria a mais adequada (mais profissional também), porém não sei como fazer, pode me ajudar?


Responder

Gostei + 0

23/04/2004

Eniorm

No form principal crie este procedimento:

procedure TSimoFormPrincipal.ProcessaMsg(var Msg: TMsg;
  var Handler: Boolean);
begin
     if (Msg.message = WM_KEYDOWN) then
        if not (Screen.ActiveControl is TCustomMemo) and
           not (Screen.ActiveControl is TButtonControl) then begin
             if not (Screen.ActiveControl is TCustomControl) then begin
                if (Msg.wParam = VK_Down) and
                   not(Screen.ActiveControl is TListBox) and
                   not(Screen.ActiveControl is TComboBox) then
                   Msg.wParam:= VK_Tab;
                if (Msg.wParam = VK_UP) and
                   not(Screen.ActiveControl is TListBox) and
                   not(Screen.ActiveControl is TComboBox) then begin
                   Msg.wParam:= VK_CLEAR;
                   Screen.ActiveForm.Perform(WM_NextDlgCtl,1,0);
                end;
                if (Msg.wParam = VK_Escape) and
                  not (Screen.ActiveForm is TSimoformPrincipal) then
                   Screen.ActiveForm.Close;
             end;
             if (Msg.wParam = VK_Return) then
                Msg.wParam:= VK_Tab;
        end;
end;


Agora no OnCreate do form principal:
Application.OnMessage := ProcessaMsg;



Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar