运行时控件的移动
在Delphi的集成开发环境中,可以用鼠标在窗体上拖动控件进行界面设计。在程序的运行期间也可以通过拖动实现控件的移动。可以使用函数Perform来传递Windows消息给控件,用来完成控件的移动。
Perform函数的原型如下:
function Perform(Msg: Cardinal; WParam, LParam: Longint): Longint;
其中参数Msg传递一个消息的ID号。消息通过Wparam、Lparam传递给进程。procedure TForm1.Edit1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
const
SC_DragMove = $F012; //$F020
begin
ReleaseCapture;
(Sender as TWinControl).Perform(WM_SysCommand, SC_DragMove, 0);
end;
在Delphi的集成开发环境中,可以用鼠标在窗体上拖动控件进行界面设计。在程序的运行期间也可以通过拖动实现控件的移动。可以使用函数Perform来传递Windows消息给控件,用来完成控件的移动。
Perform函数的原型如下:
function Perform(Msg: Cardinal; WParam, LParam: Longint): Longint;
其中参数Msg传递一个消息的ID号。消息通过Wparam、Lparam传递给进程。procedure TForm1.Edit1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
const
SC_DragMove = $F012; //$F020
begin
ReleaseCapture;
(Sender as TWinControl).Perform(WM_SysCommand, SC_DragMove, 0);
end;
我来回答这个问题
你可以调用
function ControlAtPos(const Pos: TPoint; AllowDisabled: Boolean, AllowWinControls:Boolean=False): TControl;将pos置为当前鼠标的位置即可
var
SC_MANIPULATE: Word;
begin
//光标在控件的最左侧
if (X<=Precision) and(Y>Precision) and (Y<WinControl.Height-Precision)then
begin
SC_MANIPULATE := $F001;
WinControl.Cursor := crSizeWE;
end
else //光标在控件的最右侧
if (X>=WinControl.Width-Precision) and (Y>Precision) and (Y<WinControl.Height-Precision)then
begin
SC_MANIPULATE := $F002;
WinControl.Cursor := crSizeWE;
end
else //光标在控件的最上侧
if (X>Precision) and (X<WinControl.Width-Precision) and (Y<=Precision)then
begin
SC_MANIPULATE := $F003;
WinControl.Cursor := crSizeNS;
end
else //光标在控件的左上角
if (X<=Precision) and (Y<=Precision) then
begin
SC_MANIPULATE := $F004;
WinControl.Cursor := crSizeNWSE;
end
else //光标在控件的右上角
if (X>=WinControl.Width-Precision) and (Y<=Precision) then
begin
SC_MANIPULATE := $F005;
WinControl.Cursor := crSizeNESW ;
end
else //光标在控件的最下侧
if (X>Precision) and (X<WinControl.Width-Precision) and (Y>=WinControl.Height-Precision) then
begin
SC_MANIPULATE := $F006;
WinControl.Cursor := crSizeNS;
end
else //光标在控件的左下角
if (X<=Precision) and (Y>=WinControl.Height-Precision) then
begin
SC_MANIPULATE := $F007;
WinControl.Cursor := crSizeNESW;
end
else //光标在控件的右下角
if (X>=WinControl.Width-Precision) and (Y>=WinControl.Height-Precision) then
begin
SC_MANIPULATE := $F008;
WinControl.Cursor := crSizeNWSE;
end
else //光标在控件的客户区(移动整个控件)
if (X>5) and (Y>5) and (X<WinControl.Width-5) and (Y<WinControl.Height-5) then
begin
SC_MANIPULATE := $F009;
WinControl.Cursor := crSizeAll;
end
else
begin
SC_MANIPULATE := $F000;
WinControl.Cursor := crDefault;
end;
if Shift=[ssLeft] then
begin
ReleaseCapture;
WinControl.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0); //关键行
end;
end;
即运行期动态创建一个控件,可能是按钮,也可能是Panel或者是个Tedit,如果是Panel,那么在这个上可以创建按钮之类的东东,也可以移动,调大小等都是创建控件时老指定这个控件相应的操作的,所以用如Form1.XXX,有时可能定义了没有用,甚至不能定义
有谁知道第三个问题!!!