Fórum Mudar foco ao digitar no edit #395023

03/02/2011

0

Olá,   Tenho um edit que tem a propriedade maxlength igual a 2, e preciso que qdo o usuario digitar os 2 digitos o foco seja movido automaticamente para outro edit, como faço isso?   Grato   Luiz Carlos  
Luiz Carlos

Luiz Carlos

Responder

Posts

03/02/2011

Marco Salles

é so vc fazer esta comparação no evento OnChane dele   if length(Tedit(sender).text) = 2 then  // teste a ser feito no evento onchange do edit   OutroControle.seffocus;  //isntrução a ser tomada caso teste seje verdadeiro  
Responder

Gostei + 0

03/02/2011

Luiz Carlos

Valeu Marco Antonio.   Luiz Carlos
Responder

Gostei + 0

03/02/2011

Emerson Nascimento

para não ter de indicar o componente que receberá o foco você pode pular para o próximo componente:

SendMessage(Handle, WM_NEXTDLGCTL, 0, 0); // vai para o próximo componente (TabOrder)
SendMessage(Handle, WM_NEXTDLGCTL, 1, 0); // vai para o componente anterior (TabOrder)

assim você poderá alterar a ordem dos seus componentes sem preocupar-se com o comando colocado no evento.








Responder

Gostei + 0

03/02/2011

Efraim Santana

isso deve resolver.
é só colocar o valor no maxlength  do Edit.
dessa forma funciona em qualquer lugar.

procedure TForm1.FormCreate(Sender: TObject);begin  Application.OnMessage := OnMessageNew;end;
procedure TForm1.OnMessageNew(var Msg: TMsg; var Handled: Boolean);begin  if ( Screen.ActiveControl is TEdit ) then  begin    if (Length((Screen.ActiveControl As TEdit).Text) = (Screen.ActiveControl As TEdit).MaxLength) and       ((Screen.ActiveControl As TEdit).Tag = 1)    then    begin      (Screen.ActiveControl As TEdit).Tag := 1;    end    else    begin      (Screen.ActiveControl As TEdit).Tag := 0;    end;    if ((Screen.ActiveControl As TEdit).MaxLength > 0) and       (Length((Screen.ActiveControl As TEdit).Text) = (Screen.ActiveControl As TEdit).MaxLength) and       ((Screen.ActiveControl As TEdit).Tag = 0) then    begin      (Screen.ActiveControl As TEdit).Tag := 1;      Perform(WM_NEXTDLGCTL,0,0);    end;  end;end;

Responder

Gostei + 0

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

Aceitar