我想把回车键变为TAB键
procedure TForm2.Edit2KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key=13 then
    key:=TAB键值 ;
end;
1 问一问TAB的ASCII值是多少
2 这样写能实现功能吗?如不能应怎么写呀

解决方案 »

  1.   

    procedure TCustomMISForm.TabToEnter(var Key: Word;
      Shift: TShiftState);
    begin
      if Key = VK_Return then
      begin
        Key := 0;
        if ((ActiveControl is TCustomGrid) or (ActiveControl.Parent is TCustomGrid)) then
        begin
          Key := VK_TAB;
          TMYGrid(ActiveControl as TCustomGrid).KeyDown(Key, Shift);
        end else
          Perform(CM_DIALOGKey, VK_TAB, 0);
      end;
    end;procedure TCustomMISForm.FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      FKey := KEy;
      FShift := Shift;
    end;procedure TCustomMISForm.FormKeyPress(Sender: TObject; var Key: Char);
    begin
      if Key = #13 then
      begin
        Key := #0;
        TabToEnter(FKey, FShift);
      end;
    end;
      

  2.   

    procedure TForm2.Edit2KeyPress(Sender: TObject; var Key: Char);
    begin
    if Key = #13 then
      begin
        Key := #0;
        key :=VK_TAB;//报错
      end;
    end;
    我这么写怎么报错呀
      

  3.   

    KeyPress事件中if Key = #13 then
      begin
        Key := #0;
        Keybd_Event(VK_TAB, MapvirtualKey(VK_TAB, 0), 0, 0);
      end;
      

  4.   

    Form1.KeyPreview := True ;
      

  5.   

    procedure TForm2.Edit3KeyPress(Sender: TObject; var Key: Char);
    begin
    if Key = #13 then
      begin
        Key := #0;
        Keybd_Event(VK_TAB, MapvirtualKey(VK_TAB, 0), 0, 0);
        Form2.KeyPreview := True ;
      end;
    end;
    我有几个EDIT键但有几个EDIT鍵的顺序与Tab的顺序不一样,我用的是Delphi5
    是怎么回事呢!!
      

  6.   

    To hzyood(小虾) :
    procedure TForm2.Edit2KeyPress(Sender: TObject; var Key: Char);
    begin
    if Key = #13 then
      begin
        Key := #0;
        key :=VK_TAB;//报错
      end;
    end;
    我这么写怎么报错呀
    ===================
    当然会报错呀Key的类型是Char,
    VK_TAB是Word型
    把key :=VK_TAB;//报错
    改为:
    Key := Chr(VK_TAB);//不报错
      

  7.   

    if (KEY = VK_RETURN) then
     PostMessage(Activecontrol.Handle, WM_KeyDown, VK_TAB ,0);
      

  8.   

    补充:在FormKeyDown事件中加入上面的代码就可以了。
      

  9.   

    Form1.FormKeyPress if Key = #13 then
      begin
        Key := #0;
        Keybd_Event(VK_TAB, MapvirtualKey(VK_TAB, 0), 0, 0);
      end;
    Form1.KeyPreview := True ;
      

  10.   

    Form1.KeyPreview := True ;  在属性中设置为 True