贴一段代码,不知道对你是否有用
procedure CMDialogKey(var Msg: TCMDialogKey); message CM_DIALOGKEY;
.............................................
//通过方向键控制控件的移动
procedure TDesignForm.CMDialogKey(var Msg: TCMDialogKey);
var
ShiftState: TShiftState;
tmp_x,tmp_Y:integer;
begin
ShiftState := KeyDataToShiftState(Msg.KeyData);
case Msg.CharCode of
VK_UP: //处理上箭头键按下,向上移动当前选定控件
begin
if FocusObject=nil then exit;
if (FocusObject<>DesignForm) and (FocusObject<>image1) then
begin
Tmp_Y:=(FocusObject as TGraphicControl).Top;
DEC(Tmp_Y,N);
(FocusObject as TGraphicControl).Top:=Tmp_Y;
RepDgnForm.now_Y.Caption:=IntToStr(Tmp_Y);
Tmp_Y:=Atest.Top;
DEC(Tmp_Y,N);
Atest.Top:=Tmp_Y;
end;
end;
VK_DOWN: //处理下箭头键按下,向下移动当前选定控件
begin
if FocusObject=nil then exit;
if (FocusObject<>DesignForm) and (FocusObject<>image1) then
begin
Tmp_Y:=(FocusObject as TGraphicControl).Top;
INC(Tmp_Y,N);
(FocusObject as TGraphicControl).Top:=Tmp_Y;
RepDgnForm.now_Y.Caption:=IntToStr(Tmp_Y);
Tmp_Y:=Atest.Top;
INC(Tmp_Y,N);
Atest.Top:=Tmp_Y;
end;
end;
VK_LEFT: //处理左箭头键按下,向左移动当前选定控件
begin
if FocusObject=nil then exit;
if (FocusObject<>DesignForm) and (FocusObject<>image1) then
begin
Tmp_X:=(FocusObject as TGraphicControl).Left;
DEC(Tmp_X,N);
(FocusObject as TGraphicControl).Left:=Tmp_X;
RepDgnForm.now_X.Caption:=IntToStr(Tmp_X);
Tmp_X:=Atest.Left;
DEC(Tmp_X,N);
Atest.Left:=Tmp_X;
end;
end;
VK_RIGHT: //处理右箭头键按下,向右移动当前选定控件
begin
if FocusObject=nil then exit;
if (FocusObject<>DesignForm) and (FocusObject<>image1) then
begin
Tmp_X:=(FocusObject as TGraphicControl).Left;
INC(Tmp_X,N);
(FocusObject as TGraphicControl).Left:=Tmp_X;
RepDgnForm.now_X.Caption:=IntToStr(Tmp_X);
Tmp_X:=Atest.Left;
INC(Tmp_X,N);
Atest.Left:=Tmp_X;
end;
end;
end;
inherited;//要调用缺省的处理
end;