Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   saber si se presionó Tabulador en un combobox (https://www.clubdelphi.com/foros/showthread.php?t=61684)

Lizette 18-11-2008 09:44:53

saber si se presionó Tabulador en un combobox
 
Hola, tengo un combobox validado, de tal manera q si presiona enter o tabulador y no hay nada dentro del combo, se anula la tecla y se queda dentro del combo, si el combo contiene algo, se brinca al siguiente edit con tabulador o enter. El caso es q con enter si funciona pero con tabulador no..

Código Delphi [-]

procedure TfrmProductoAdd.ComboClasKeyPress(Sender: TObject;
  var Key: Char);
begin
if (Length(ComboClas.Text)=0) and (Key<>Char(13))then
   Key:=Char(0);
 if ((Key=Char(13)) and (Length(ComboClas.Text)<>0)) then
 begin
  Key:=Char(0);
  EditLab.SetFocus;
 end;
end;

procedure TfrmProductoAdd.ComboClasKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Length(ComboClas.Text)=0) and (Key<>9)then
   Key:=0;
 if ((Key=9) and (Length(ComboClas.Text)<>0)) then
 begin
  Key:=0;
  EditLab.SetFocus;
 end;  
end;

Caro 18-11-2008 14:07:45

Hola Lizette, parece que con los eventos OnKeyPress, OnKeyDown no se detecta la tecla Tab, con el OnKeyUp mas o menos pero detecta cuando se ha echo Tab del otro control, lo que se me ocurre es que utilices ApplicationEvent y ahí detectes la tecla, sería algo así.

Código Delphi [-]
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
  var Handled: Boolean);
begin
 if (Msg.message=WM_KEYDOWN) and (Msg.wParam=vk_tab) then
  if ActiveControl = ComboBox1 then //Si es el control es el ConboBo1
   if Trim(ComboBox1.Text)='' then //Si esta vacio
    ComboBox1.SetFocus; //Pero esta parte no funciona.
end;

Detecta la tecla, identifica al combobox, pero no funciona el SetFocus.
Saluditos

Caro 18-11-2008 14:27:10

Hola de nuevo, acabo de hacer una pruebita y si funciona, al igual que se hace en los eventos OnKeyDown..., podemos anular la tecla con el 0, en vez del SetFocus, colocas esta linea.

Código Delphi [-]
 Msg.wParam := 0;

Saluditos

Lizette 19-11-2008 02:14:33

Gracias Caro :)


La franja horaria es GMT +2. Ahora son las 15:26:54.

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