procedure ReturnKey(pFormHandle:THandle;pKey:word); begin if pKey=VK_RETURN then PostMessage(pFormHandle,WM_KEYDOWN,VK_TAB,0); end;
在keypress事件中加入下面代码;然后别的控件直接应用此时间就可以了 if key = #13 then SendMessage(Handle, WM_NEXTDLGCTL, 0, 0);
procedure TForm1.Button1KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then edit1.SetFocus;//其中edit为你要的控件,但SpeedButton除外(因为它没有焦点) end;
if key = #13 then key:=#9;
总结一下: 有两个方法:VCL & Windows VCL 拦截OnKeyPress Windows 发送按键消息! 本质一样! 只是形式不同而已! 建议用Windows的发送机制 速度快!
procedure TMainForm.DoEnterAsTab(var Msg: TMsg; var Handled: Boolean); begin if Msg.Message = WM_KEYDOWN then begin if Msg.wParam = VK_RETURN then Keybd_event(VK_TAB, 0, 0, 0); end; //if end; form的oncreate事件中写入 Application.OnMessage := DoEnterAsTab; 就可以了,一劳永益
把keypreview设置为true 再在Onkeydown过程中加入以下代码: if Key=VK_Return then PerForm(WM_NEXTDLGCTL,0,0);
if key = #13 then
key:=#9;
begin
if pKey=VK_RETURN then
PostMessage(pFormHandle,WM_KEYDOWN,VK_TAB,0);
end;
if key = #13 then
SendMessage(Handle, WM_NEXTDLGCTL, 0, 0);
begin
if key=#13 then
edit1.SetFocus;//其中edit为你要的控件,但SpeedButton除外(因为它没有焦点)
end;
key:=#9;
有两个方法:VCL & Windows
VCL 拦截OnKeyPress
Windows 发送按键消息!
本质一样!
只是形式不同而已!
建议用Windows的发送机制
速度快!
begin
if Msg.Message = WM_KEYDOWN then
begin
if Msg.wParam = VK_RETURN then
Keybd_event(VK_TAB, 0, 0, 0);
end; //if
end;
form的oncreate事件中写入
Application.OnMessage := DoEnterAsTab;
就可以了,一劳永益
再在Onkeydown过程中加入以下代码:
if Key=VK_Return then
PerForm(WM_NEXTDLGCTL,0,0);