也就是說當按Enter鍵的時候,產生的效果是按了Tab鍵.
下面是我經常使用的方法:
在你的數據模塊中,添加如下代碼:
interface
。。。。。。
type
TMessageHandler = class //使得回車消息轉換成Tab消息
class procedure AppMessage(var Msg:TMsg;var Handled:Boolean);
end;
implementation
class procedure TMessageHandler.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
if Msg.message=WM_KEYDOWN then
if (Msg.wParam=VK_RETURN ) and
(
(Screen.ActiveForm.ActiveControl is TEdit) or
(Screen.ActiveForm.ActiveControl is TComboBox) or
(Screen.ActiveForm.ActiveControl is TCheckBox) or
(Screen.ActiveForm.ActiveControl is TRadioButton)
//可以添加需要的控件
)
then
begin
Msg.wParam:=VK_TAB;
end
else if (Msg.wParam=VK_RETURN) and
(
(Screen.ActiveForm.ActiveControl is TDBGrid)
)
then
begin
with Screen.ActiveForm.ActiveControl do
begin
if Selectedindex<(FIEldCount-1) then
Selectedindex:=Selectedindex+1{ 移動到下一字段}
else
Selectedindex:=0;
end;
end;
end;
為了使得整個應用程序都能夠實現主要的功能,在主窗體的OnCreate事件中添加如下代碼:
procedure TfmMain.FormCreate(Sender: TObject);
begin
Application.OnMessage:=TMessageHandler.AppMessage;
end;
到此為止,你的應用程序已經實現了這個Enter->Tab的轉換.