在Edit1.OnKeyDown事件中写 if Key=#13 then Edit2.SetFouce; end;
edit1,edit2的onKeyPress指向同一个。 procedure TForm1.edtKeyPress(Sender: TObject; var Key: Char); begin if key=#13 then postmessage(handle,WM_NEXTDLGCTL,0,0); end;
要是总共有10个Edit呢,一个一个的跳转,怎么做啊
每个Edit都连接上同一个事件,代码就用我那段就可以了。
procedure TFormTemplate.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); Var GoNext: Boolean; begin if Key = VK_RETURN then //如果按下了回车键 begin GoNext:=True; //如果当前控件不是Memo控件,并不是下拉的TRxDBLookupCombo控件 if ( Sender as TForm ).ActiveControl.ClassType = TListBox then GoNext:= False; if ( Sender as TForm ).ActiveControl.ClassType =TDBMemo then GoNext:=False; if ( Sender as TForm ).ActiveControl.ClassType = TMemo then GoNext:= False; if ( Sender as TForm ).ActiveControl.ClassType = TComboBox then if ( ( Sender as TForm ).ActiveControl As TComboBox ).DroppedDown then GoNext:= False; if GoNext then begin Key := Ord(0); //吃掉回车键 Perform(WM_NEXTDLGCTL, 0, 0); //移动到下一个控制 end; end;
一个一个地跳转,不就是用 chechy(chechy) 的方法吗? 设置Form的KeyPreview为True,在Form的OnKeyDown事件中 if Key = VK_RETURN then Perform(WM_NEXTDLGCTL, 1, 0);
修改一下,去掉声音: if Key = VK_RETURN then begin Perform(WM_NEXTDLGCTL, 1, 0); Key:=0; end;
Edit2.SetFocus
if Key=#13 then
Edit2.SetFouce;
end;
procedure TForm1.edtKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
postmessage(handle,WM_NEXTDLGCTL,0,0);
end;
Shift: TShiftState);
Var
GoNext: Boolean;
begin
if Key = VK_RETURN then //如果按下了回车键
begin
GoNext:=True;
//如果当前控件不是Memo控件,并不是下拉的TRxDBLookupCombo控件
if ( Sender as TForm ).ActiveControl.ClassType = TListBox then GoNext:= False;
if ( Sender as TForm ).ActiveControl.ClassType =TDBMemo then GoNext:=False;
if ( Sender as TForm ).ActiveControl.ClassType = TMemo then GoNext:= False;
if ( Sender as TForm ).ActiveControl.ClassType = TComboBox then
if ( ( Sender as TForm ).ActiveControl As TComboBox ).DroppedDown then GoNext:= False;
if GoNext then
begin
Key := Ord(0); //吃掉回车键
Perform(WM_NEXTDLGCTL, 0, 0); //移动到下一个控制
end;
end;
设置Form的KeyPreview为True,在Form的OnKeyDown事件中
if Key = VK_RETURN then
Perform(WM_NEXTDLGCTL, 1, 0);
if Key = VK_RETURN then
begin
Perform(WM_NEXTDLGCTL, 1, 0);
Key:=0;
end;
Edit2.SetFocus