怎样用回车键代替TAB键,实现焦点在控件间的移动。
以前见过,没用就忘了。望各位大侠,小虾多多指教。

解决方案 »

  1.   

    在onkeydown事件中判断key是否回车键,是就用setfoucs转移焦点
      

  2.   

    Procedure TForm1.FormKeyPress(Sender:Tobject;Var Key:Char);
    Begin
     if key=#13 then { 判断是按执行键}
     if not (ActiveControl is TDbgrid) Then
     Begin { 不是在TDbgrid控件内}
      key:=#0;
      perform(WM_NEXTDLGCTL,0,0);{移动到下一个控件}
     end else
     if (ActiveControl is TDbgrid) Then{是在 TDbgrid 控件内}
     begin
      With TDbgrid(ActiveControl) Do
      if Selectedindex<(FieldCount-1) then
      Selectedindex:=Selectedindex+1{ 移动到下一字段}
      else Selectedindex:=0;
     end;
    End;
      

  3.   

    同意 bluemeteor(挂月||╭∩╮(︶︿︶)╭∩╮)!
      

  4.   

    如果控件是Dbgrid,在ONKEYPRESS事件中:
    if Key = #13 then
    if ActiveControl = DBGrid1 then begin
    TDBGrid(ActiveControl).SelectedIndex := TDBGrid(ActiveControl).SelectedIndex + 1;
    Key := #0;
    其它则在ONKEYPRESS事件中写入另一控件.setfocus
      

  5.   

    同意 bluemeteor(挂月||╭∩╮(︶︿︶)╭∩╮)!