如何确定回车键的使用(50分)

  • 主题发起人 主题发起人 baijing_dt
  • 开始时间 开始时间
B

baijing_dt

Unregistered / Unconfirmed
GUEST, unregistred user!
在一面板输入多个数据框的时候,如何能够用回车键而不是用Tab键来控制输入框的焦点!
 
tab=enter
在按键事件中,当按回车键时模拟按TAB就OK啦。
 
在空间的OnKeyPress事件里面加入
if key=#13 then ActiveControl=Edit2;

Edit2表示下一个输入筐
 
if key=VK_RETURN then
postmessage(self.handle,wm_keydown,vk_tab,0);

用postmessage吧。Enter的作用和Tab是一模一样的。
 
procedure TLandF.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = 13 then
begin
Edit2.TabStop := True;
Edit2.SetFocus;
end;
end;
 
if (key=13) then
Edit2.setfocus;
 
在窗体事件KeyPress
if (Key = #13) then
begin
Key := #0;
perform(WM_NEXTDLGCTL, 0, 0);
end;
并设窗体keypreview属性为真
 
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = vk_return then
radiobutton1.SetFocus ;
end;
 
procedure TFormWindowDef1inModify.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then PostMessage(Handle, WM_KEYDOWN, VK_TAB, 0);
end;

楼主可别忘了,还应该设置FormWindowDef1inModify.KeyPreview:=True;才行。
 
procedure dodo(v: TComponent; Command: string);
var
i: integer;
begin
if (v is Tform) then
with V as Tform do
begin
for i := 0 to ComponentCount - 1 do
begin
if (Components is TRzBitBtn) or (Components is TRzBmpButton) or (Components is TButtonControl) then
if TWinControl(Components).CanFocus then
if TWinControl(Components).Parent.CanFocus then
if pos(Command, TRzBitBtn(Components).Caption) > 0 then
begin
try
TWinControl(Components).SetFocus;
TButton(Components).Click;

except
;
end
end;

if (Components is TFrame) then
dodo(Components, Command);
end;
end;
if (v is TFrame) then
with V as TFrame do
begin
for i := 0 to ComponentCount - 1 do
begin
if Components is TRzBitBtn then
if TRzBitBtn(Components).CanFocus then
if TRzBitBtn(Components).Parent.CanFocus then
if pos(Command, TRzBitBtn(Components).Caption) > 0 then
begin
TRzBitBtn(Components).SetFocus;
TRzBitBtn(Components).Click;
end;

if (Components is TFrame) then
dodo(Components, Command);
end;
end;

end;

procedure TFrm_main.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
var
OldAC: TWinControl;

function isLastInput(V: TWinControl): Boolean;
var
i: integer;
begin
result := false;
if v is TButton then
exit;
if v is TBitBtn then
exit;
if v is TRzBitBtn then
exit;
if v.Parent = nil then
exit;
with v.Parent do
begin
for i := 0 to ControlCount - 1 do
// if (Controls is TRzEdit) or (Controls is TRzNumericEdit) then
if (Controls is TWinControl) then
if TWinControl(Controls).CanFocus then
if v.TabOrder < TWinControl(Controls).TabOrder then
begin
exit;
end;
end;
result := true;
end;

begin

case Msg.message of
WM_CHAR:
case Msg.wParam of
34: Handled := true; //"
38: Handled := true; //'
39: Handled := true; //&
//94:Handled:=true; //^
124: Handled := true; //|

end;
WM_KEYDOWN:
begin
if screen.ActiveForm <> nil then
if screen.ActiveForm.Tag <> 999 then
exit;
OldAC := screen.ActiveControl;
case Msg.wParam of
vk_return:
if screen.ActiveControl is TRzButtonEdit then
with TRzButtonEdit(screen.ActiveControl) do
begin
if assigned(OnButtonClick) then
OnButtonClick(screen.ActiveControl);
end

else
if not (screen.ActiveControl is TCustomGrid) then
if not (screen.ActiveControl is TRzBitBtn) then
if not (screen.ActiveControl is TBitBtn) then
if not (screen.ActiveControl is TButton) then
if (not (screen.ActiveControl is Tmemo)) then
if screen.ActiveControl.Tag <> 999 then
begin
if isLastInput(screen.ActiveControl) then
begin
keybd_event(VK_F2, 0, 0, 0);
Handled := true;
exit;
end;

screen.ActiveForm.Perform(WM_NEXTDLGCTL, 0, 0);
Handled := true;
if screen.ActiveControl is TRzBitBtn then
begin
TRzBitBtn(screen.ActiveControl).Click;
end;

end;
VK_ESCAPE:
begin
if screen.ActiveForm <> nil then
dodo(screen.ActiveForm, 'Esc');
end;

VK_F2:
begin
if screen.ActiveForm <> nil then
begin
dodo(screen.ActiveForm, 'F2');
dodo(screen.ActiveForm, '确定');
setFouceFirst(OldAC);
end;
end;
VK_F3:
begin
if screen.ActiveForm <> nil then
dodo(screen.ActiveForm, 'F3');
end;

VK_F4:
begin
if screen.ActiveForm <> nil then
dodo(screen.ActiveForm, 'F4');
end;
VK_F5:
begin
if screen.ActiveForm <> nil then
dodo(screen.ActiveForm, 'F5');
end;
VK_F6:
begin
if screen.ActiveForm <> nil then
dodo(screen.ActiveForm, 'F6');
end;
VK_F7:
begin
if screen.ActiveForm <> nil then
dodo(screen.ActiveForm, 'F7');
end;
VK_F8:
begin
if screen.ActiveForm <> nil then
dodo(screen.ActiveForm, 'F8');
end;
VK_F9:
begin
if screen.ActiveForm <> nil then
dodo(screen.ActiveForm, 'F9');
end;
VK_F10:
begin
if screen.ActiveForm <> nil then
dodo(screen.ActiveForm, 'F10');
end;
end;

end;

end;

end;
 
procedure TFormWindowDef1inModify.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then SelectNext(ActiveControl,true,true);
end;
 
多人接受答案了。
 
后退
顶部