-
-
[求助]如何让鼠标跟随文字,脱离Form1窗体使用?当作录像时的水印!
-
发表于: 2019-12-17 16:30 2370
-
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,stdctrls,extctrls; //后两个为动态创建控件的类 type TForm1 = class(TForm) Timer1: TTimer; procedure FormCreate(Sender: TObject); procedure FormDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); procedure Timer1Timer(Sender: TObject); procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); private { Private declarations } public { Public declarations } end; var Form1: TForm1; lab : array[0..255] of TLabel; mx,my:integer; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var i,t:integer; s:string; begin s:='欲 穷 千 里 目 , 更 上 一 层 楼 。'; //作业:改为汉字 ,有字体、颜色 t:=length(s); for i:=0 to 11 do begin lab[i]:=TLabel.Create(Application.MainForm); lab[i].Parent := self; lab[i].caption:=copy(s,i*4,4)+' '; lab[i].Left :=50+60*i; lab[i].DragMode := dmAutomatic; lab[i].Font.color:=clRed; //设置颜色 lab[i].Font.Name :='隶书'; //设置字体 //设置每一个字的颜色都不同 case i of 0: lab[i].Font.color:=clRed; 1: lab[i].Font.color:=clGreen; 2: lab[i].Font.color:=clFuchsia; end; //self.Color:=rgb(random(2147483647)); // self.Color:=floor(random(2147483647)); end; end; procedure TForm1.FormDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); begin // mx:=x; // my:=y; end; procedure TForm1.Timer1Timer(Sender: TObject); var i:integer; begin for i:= 11 downto 1 do //从后往前逐一给每个字符新的位置坐标 begin lab[i].Left :=lab[i-1].Left +50; lab[i].Top :=lab[i-1].Top ; end; lab[0].Left:=mx+50; //第一个点的坐标为当前鼠标的坐标mx,my lab[0].Top:=my; end; procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin mx:=x; my:=y; end; end.
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!
最后于 2019-12-17 16:31
被ninebell编辑
,原因:
赞赏
他的文章
看原图
赞赏
雪币:
留言: