关于动态创建控件的一个问题。 我动态的创建了一个label控件,定义了它的onmousemove过程,想在onmousemove事件中实现label的移动,但不知代码如何写,请各位帮一下忙。谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 通过MouseMove事件、DragOver事件、EndDrag事件实现,例如在PANEL上的LABEL:var xpanel,ypanel,xlabel,ylabel:integer;PANEL的MouseMove事件:xpanel:=x;ypanel:=y;PANEL的DragOver事件:xpanel:=x;ypanel:=y;LABEL的MouseMove事件:xlabel:=x;ylabel:=y;LABEL的EndDrag事件:label.left:=xpanel-xlabel;label.top:=ypanel-ylabel; 不知道新建的label的name要如何写,???.left???.top???不知道要写什么。 外加panel增加EXE文件大小,而且大小巨增,用StaticText1控件,,况且LABEL不支持句柄procedure TForm1.StaticText1MouseMove(Sender: TObject; Shift: TShiftState;X, Y: Integer);beginReleaseCapture;form1.StaticText1.Perform(WM_SYSCOMMAND, $F012, 0);end;祝:身体健康,提前完工:) unit MovePanel;interfaceuses Windows, Classes, Controls, ExtCtrls, Forms;type TMovePanel = class(TPanel) private { Private declarations } PrePoint: TPoint; Down: Boolean; protected { Protected declarations } public { Public declarations } constructor Create(AOwner:TComponent); override; procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; published { Published declarations } end;procedure Register;implementationprocedure Register;begin RegisterComponents('Samples', [TMovePanel]);end;{ TMovePanel }constructor TMovePanel.Create(AOwner: TComponent);begin inherited Create(AOwner);end;procedure TMovePanel.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin if (Button = MBLeft) then begin Down := true; Screen.Cursor := crSizeAll; GetCursorPos(PrePoint); end; if assigned(OnMouseDown) then OnMouseDown(Self, Button, Shift, X, Y);end;procedure TMovePanel.MouseMove(Shift: TShiftState; X, Y: Integer);Var NowPoint: TPoint;begin if Down then begin GetCursorPos(NowPoint); Self.Parent.Left := Self.Parent.Left + NowPoint.X - PrePoint.X; Self.Parent.Top := Self.Parent.Top + NowPoint.Y - PrePoint.Y; PrePoint := NowPoint; end; if Assigned(OnMouseMove) then OnMouseMove(Self, Shift, X, Y);end;procedure TMovePanel.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin if (Button = MBLeft) and Down then begin Down := False; Screen.Cursor := crDefault; end; if assigned(OnMouseUp) then OnMouseUp(Self, Button, Shift, X, Y);end;end. 上面是完整的代码,用个TMovePanel组件以后就随时可以用了 指针的运算安全吗? 一个函数/过程里.有几个参数.怎么知道? 编写的dll为什么不能注册? 求html浏览编辑器控件 各位高手好 提一个非常非长奇怪的问题?帮忙回答一下 急急急急急!!!!!都来帮忙!!! 请教一个SQL 语句的写法。在线等待!! 数据库存取大文本 低手问高手:这样的类怎样写? 给初学DELPHI的人一些建议!!!! 救!在Delphi中用什么报表可实现页统计和页累计!怎样实现!谢谢! 高手来罐水 高手来罐水 高手来罐水 高手来罐水-------谢谢 当场给分
var xpanel,ypanel,xlabel,ylabel:integer;
PANEL的MouseMove事件:xpanel:=x;ypanel:=y;
PANEL的DragOver事件:xpanel:=x;ypanel:=y;
LABEL的MouseMove事件:xlabel:=x;ylabel:=y;
LABEL的EndDrag事件:label.left:=xpanel-xlabel;label.top:=ypanel-ylabel;
???.left
???.top
???不知道要写什么。
而且大小巨增,
用StaticText1控件,,况且LABEL不支持句柄procedure TForm1.StaticText1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
ReleaseCapture;
form1.StaticText1.Perform(WM_SYSCOMMAND, $F012, 0);
end;祝:身体健康,提前完工:)
Windows, Classes, Controls, ExtCtrls, Forms;type
TMovePanel = class(TPanel)
private
{ Private declarations }
PrePoint: TPoint;
Down: Boolean;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner:TComponent); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
published
{ Published declarations }
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('Samples', [TMovePanel]);
end;{ TMovePanel }constructor TMovePanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;procedure TMovePanel.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
if (Button = MBLeft) then
begin
Down := true;
Screen.Cursor := crSizeAll;
GetCursorPos(PrePoint);
end; if assigned(OnMouseDown) then
OnMouseDown(Self, Button, Shift, X, Y);
end;procedure TMovePanel.MouseMove(Shift: TShiftState; X, Y: Integer);
Var
NowPoint: TPoint;
begin
if Down then
begin
GetCursorPos(NowPoint);
Self.Parent.Left := Self.Parent.Left + NowPoint.X - PrePoint.X;
Self.Parent.Top := Self.Parent.Top + NowPoint.Y - PrePoint.Y;
PrePoint := NowPoint;
end; if Assigned(OnMouseMove) then
OnMouseMove(Self, Shift, X, Y);
end;procedure TMovePanel.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
if (Button = MBLeft) and Down then
begin
Down := False;
Screen.Cursor := crDefault;
end; if assigned(OnMouseUp) then
OnMouseUp(Self, Button, Shift, X, Y);
end;end.
用个TMovePanel组件
以后就随时可以用了