以前做显示屏的时候做的,试试看 可以选择路径,速度,停留时间!unit aledtextclass;interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,stdctrls,fileoperdll,ledtextdialog,aledcommonfuc; type TTextMoveStyle=(msdown,msup); {关键点结构} { keypoint=record locate : tpoint; //关键点位置 waittime : integer; //在关键点停留时间 speed : integer; //从本点出发的速度 end; } {文字对象} TLedText=class(TLabel) public code : string; //对象唯一标志符 starttime : integer; //开始演播时间 totalpath : integer; //关键点总数 path : array of keypoint; //关键点数组 oldpage : integer; //上次中断帧 stime : extended; selected : boolean; //是否被选中 showpath : boolean; //是否显示路径 mousedown:boolean; //鼠标是否被按下 oldx,oldy:integer; newtext:boolean; //新建文本 times:integer; published properdlg:Tledtextproperdlg; constructor Create(AOwner : TComponent); override; destructor destroy; override; procedure WMSetFocus(var Message: TWMLBUTTONUP); message WM_LBUTTONUP; procedure WMPaint(var Message: TWMPaint); message WM_Paint; procedure WMLButtonDown(var Message: TWMLBUTTONDOWN); message WM_LBUTTONDOWN; procedure WMMOUSEMOVE(var Message: TWMMOUSEMOVE); message WM_MOUSEMOVE; function savetostrings:tstrings; procedure loadfromstrings(strs:tstrings); procedure setnamestr(str:string); procedure setselected(sel:boolean); function GetNameStr:string; public {显示设置对话框} function SetProperty:boolean; function GetStep(curpage: integer;var step:integer): integer; {对象演示函数} procedure play(curpage:integer;cas:tcanvas); end;function GetPoint(t:extended;s:integer;p1,p2:tpoint):tpoint; function GetTwoPointLength(p1,p2:tpoint):extended;implementation uses unit1,main; { TLedText }constructor TLedText.Create(AOwner: TComponent); begin inherited; times:=0; showpath:=true; end;destructor TLedText.destroy; begin inherited;end; { 返回值:-1 表示不在该路径的内部 0 表示处于某点的等待状态 1 表示处于某段} function TLedText.GetNameStr: string; var str:string; sel:integer; begin getcontrolnamestr(name); result:=str; end;function TLedText.GetStep(curpage: integer;var step:integer): integer; var i:integer; temptotaltime,t,totaltime:extended; begin {计算每段需要花费的时间} if totalpath<=1 then begin result:=-1; exit; end; totaltime:=starttime; for i:=0 to totalpath-2 do begin totaltime:=totaltime+path[i].waittime; {如果在某点的等待时间内} if curpage<=totaltime then begin result:=0; exit; end; {计算当前点到下一点需要的时间} t:=gettwopointlength(path[i].locate,path[i+1].locate) /path[i].speed ; temptotaltime:=totaltime; totaltime:=totaltime+t; {在两点中间时候} if curpage<=totaltime then begin stime:=curpage*1.0-temptotaltime; step:=i+1; result:=1; exit; end; end; result:=-1; end;procedure TLedText.loadfromstrings(strs: tstrings); var i:integer; str:string; begin if strs.count<6 then exit; font.name:=strs[1]; font.height:=strtoint(strs[2]); font.color:=strtoint(strs[3]); left:=strtoint(strs[4]); top:=strtoint(strs[5]); if strs[6]='不透明' then transparent:=false else transparent:=true; caption:=''; str:=''; for i:=0 to strs.count-8 do begin if i=strs.count-8 then str:=str+strs[i+7] else str:=str+strs[i+7]+#13+#10; end; caption:=str; end;procedure TLedText.play(curpage:integer;cas:tcanvas); var i,step,ret:integer; p:tpoint; begin {计算在时刻 curpage 时文字应处于的位置} ret:=GetStep(curpage,step); // form1.Label4.caption:=inttostr(step); if (ret=-1) then begin left:=path[0].locate.x; top:=path[0].locate.y; end; if ret<>1 then exit; {获取文本位置} if step=2 then begin end; p:=GetPoint(stime,path[step-1].speed,path[step-1].locate,path[step].locate); left:=p.x; top:=p.y; // form1.label1.caption:='x:'+inttostr(left); // form1.label2.caption:='y:'+inttostr(top); end;function TLedText.savetostrings: tstrings; var strs:tstrings; i:integer; str,tempstr:string; begin strs:=tstringlist.create; strs.add('[文本]'); strs.Add(font.name); strs.add(inttostr(font.height)); strs.add(inttostr(font.color)); strs.add(inttostr(left)); strs.add(inttostr(top)); if transparent then strs.add('透明') else strs.add('不透明'); strs.add(caption); result:=strs; end;procedure TLedText.setnamestr(str: string); var tempstr:string; begin tempstr:=copy(name,1,4); name:=tempstr+str; end;function TLedText.SetProperty:boolean; var strs:tstrings; sel,i,ret:integer; str:string; begin application.CreateForm(Tledtextproperdlg,properdlg); try showpath:=false; ledtextdialog.ledtransparent:=transparent; properdlg.Memo1.font:=font; properdlg.memo1.lines.clear; properdlg.editstart.text:=inttostr(starttime); if not newtext then begin properdlg.memo1.lines.add(Caption); properdlg.Edit1.text:=getcontrolnamestr(name); end; properdlg.edit1.text:=getcontrolnamestr(name); {设置运动属性} ledtextdialog.totalpath:=totalpath; setlength(ledtextdialog.path,totalpath); for i:=0 to totalpath-1 do begin ledtextdialog.path[i].locate:=path[i].locate; ledtextdialog.path[i].waittime:=path[i].waittime; ledtextdialog.path[i].speed:=path[i].speed; end; unit1.showpath:=true; if totalpath<>0 then begin properdlg.pathcombox.Items.clear; for i:=0 to totalpath-1 do begin properdlg.pathcombox.Items.add(inttostr(i+1)); end; end else begin properdlg.pathcombox.items.clear; properdlg.Editx.text:=''; properdlg.Edity.text:=''; properdlg.Editspeed.text:=''; properdlg.Editstay.text:=''; end; properdlg.newtext:=newtext; properdlg.textname:=getcontrolnamestr(name); if newtext then begin properdlg.memo1.font.color:=clred; end; ret:=properdlg.showmodal; str:=caption; caption:=''; code:=properdlg.Edit1.text; if ret=mrok then result:=true else result:=false; if ret<>mrok then begin caption:=str; exit; end; strs:=properdlg.memo1.lines; for i:=0 to strs.count-1 do begin if i<>strs.count-1 then begin caption:=caption+strs[i]+#13+#10; end else caption:=caption+strs[i]; end; transparent:=properdlg.transbtn.checked; font:=ledtextdialog.ledfont; setcontrolnamestr(name,properdlg.edit1.text); {设置开始时间} {设置路径属性} totalpath:=ledtextdialog.totalpath; setlength(path,totalpath); for i:=0 to totalpath-1 do begin path[i].locate:=ledtextdialog.path[i].locate; path[i].waittime:=ledtextdialog.path[i].waittime; path[i].speed:=ledtextdialog.path[i].speed; end; showhint:=true; hint:=code; finally properdlg.Destroy; showpath:=false; form1.Invalidate; selected:=true; end; end;procedure TLedText.setselected(sel: boolean); var str1,str2:string; len:integer; begin name:=setcontrolselected(name,sel); end;procedure TLedText.WMLButtonDown(var Message: TWMLBUTTONDOWN); begin inherited; mousedown:=true; oldx:=mouse.cursorpos.x; oldy:=mouse.cursorpos.y;end; procedure TLedText.WMMOUSEMOVE(var Message: TWMMOUSEMOVE); var p,p1:tpoint; begin inherited; if mousedown then begin {将文本移动到指定位置} p:=mouse.CursorPos; left:=left+p.x-oldx; top:=top+p.y-oldy; oldx:=p.x; oldy:=p.y; end; end;procedure TLedText.WMPaint(var Message: TWMPaint); var rect:trect; r,g,b,i:integer; begin inherited; {} rect.left:=0; rect.Top:=0; rect.Right:=width; rect.bottom:=height; if selected then begin canvas.Brush.Style:=bsclear; canvas.Pen.Style:=psDot; canvas.pen.color:=clwhite+10; canvas.Rectangle(rect); end; showpath:=false; if showpath then begin form1.canvas.moveto(path[0].locate.x,path[0].locate.y); for i:=1 to totalpath-1 do begin if totalpath=0 then break; {画路径线} form1.canvas.Pen.color:=clred; form1.Canvas.lineto(path[i].locate.x,path[i].locate.y); form1.canvas.moveto(path[i].locate.x,path[i].locate.y); end; end;end;procedure tledtext.WMSetFocus(var Message: TWMLBUTTONUP); begin inherited; mousedown:=false; selected:=not selected; Invalidate; {如果处于文字状态则修改} setselected(selected); if mainform.textbutton.down then begin newtext:=false; setproperty; end; end;{通用函数} {计算两点已经经历的时间的位置} function GetPoint(t:extended;s:integer;p1,p2:tpoint):tpoint; var p:tpoint; thr,temp,len,tempreal:real; intx,floatx:integer; thrthr:real; begin if (p2.x=p1.x) then begin end; temp:=(p2.y-p1.y) / (p2.x-p1.x); tempreal:=temp; thr:=arctan(abs(temp)); thrthr:=thr; if tempreal>0 then begin if p1.x>p2.x then temp:=p1.x-(t*s)*cos(thrthr) else temp:=p1.x+(t*s)*cos(thrthr); val(floattostr(temp),intx,floatx); p.x:=intx; if p1.y>p2.y then temp:=p1.y-(t*s)*sin(thrthr) else temp:=p1.y+(t*s)*sin(thrthr); val(floattostr(temp),intx,floatx); p.y:=intx; end else begin if p1.x>p2.x then temp:=p1.x-(t*s)*cos(thrthr) else temp:=p1.x+(t*s)*cos(thrthr); val(floattostr(temp),intx,floatx); p.x:=intx; if p1.y>p2.y then temp:=p1.y-(t*s)*sin(thrthr) else temp:=p1.y+(t*s)*sin(thrthr); val(floattostr(temp),intx,floatx); p.y:=intx; end; result:=p;end; {计算当前时刻位于哪两点之中} function GetTwoPointLength(p1,p2:tpoint):extended; var x:extended; begin x:=sqr(p2.y-p1.y)+sqr(p2.x-p1.x); result:=sqrt(x); end;end.
To lichp(海风): 你的方法是对的,但是效果很差劲:闪烁得很厉害! To jjdelphi(星辰): 实在不想写代码,上次给你的代码原理就是那个样子了。一头雾水的代码我没有测试,也许可以,你看看吧。
下面代码是个简单的字幕在 Form1 上从下往上移动的例子, 主要是利用 Canvas.TextOut(X,Y,'String') 方法,不断的 改变它的 X 或 Y 的值,实现左右或上下移动。 要改变字体,直接改变 Canvas.Font 就可以。 你要做的效果可以参照这种方法。下面的代码运行通过, 你可以看一下它运行时的效果。 procedure TForm1.Timer1Timer(Sender: TObject); begin if Height-i<0 then i:=0; // i 是一个全局的整型变量; Timer1.Interval :=100; Canvas.TextOut(100,Height - i,'AAA'); if i=Round(Height/2) then Timer1.Interval:=2000; // 当字符在中央时,让它停留2秒钟; i:= i + 1; // 改变 i 的值实现字符上移; end;procedure TForm1.FormCreate(Sender: TObject); begin i:=0; Canvas.Brush.Color :=color; // 用 Form1 的背景色填充画布,要不然画布是白色。 Canvas.FillRect(Rect(Left,Top,Left+Width,Top+Height)); end;
能给我一个完整的程序吗?带Form的
to Apollo47():窗口改变一下,原来动的字符就不动了,出现一个新的移动字符 让文件的每一行一行一行的上升,该怎样实现循环?
to Kingron(WinAPI):帮我写写代码吧,我写的时候遇到太多的问题了,你写写我学习学习
当你想要某行字符串停止时只要不改变 Canvas.TextOut(x, y,'aaa') 中的 x, y 就可以。 比如在他前面加上一句 if (height-i)=100 then i:=height-100; 这样 height-i 的值就不会再变。字符串也就不会动了。 其实我上面代码的第一句 if Height-i<0 then i:=0;就是 实现循环的。
下面这段代码是:当字符串 'AAA' 移到中央时停止不动, 字符串 'BBB' 开始从下出来,当 'BBB' 也移到中央时, 停止两秒钟,接着 'AAA' 开始向上隐去,当 'AAA' 看不到 时, 'BBB' 开始向上隐去,当 'BBB' 也看不到时,回到初始 状态,进行循环。 你可以运行这段代码看看效果,读懂了代码,相信你的问题就 可以解决了。我的 E_mail : [email protected] oicq: 22309797 procedure TForm1.Timer1Timer(Sender: TObject); begin timer1.Interval :=10; if flag=false then // 向上拉出 if i<(round(height/2)) then begin canvas.TextOut(100,height-i,'AAA'); I:=I+1; end else if j<(Round(height/2)) then begin Canvas.TextOut(200,height-j,'BBB'); j:=J+1; end else begin timer1.Interval :=2000; flag:=true; end ;if flag=true then // 向上隐去 if i<height+15 then // 加15是字符串的高度 begin Canvas.TextOut(100,height-i,'AAA'); i:=i+1; end else if j<Height+15 then begin Canvas.TextOut(200,height-j,'BBB'); j:=j+1; end else begin flag:=false; i:=0; j:=0; end; end;procedure TForm1.FormCreate(Sender: TObject); begin // i , j, flag 是全局变量; i:=0; j:=0; flag:=false; Canvas.Brush.Color :=color; Canvas.FillRect(Rect(0, 0, Width, Height)); end;
本文讨论先到这里,只是还有一点小问题.我把修改了的程序贴到这里,大家看看,希望能对象我一样的初学者有所帮助.由于我把可用分兑换掉了,一次加分很少,我想能多加分后把分加给大家,行吗? 还不能实现从一侧飞入的效果 unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, ColorGrd, RxCombos;type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; OpenDialog1: TOpenDialog; Button2: TButton; Button3: TButton; TrackBar1: TTrackBar; Panel1: TPanel; Panel2: TPanel; Panel3: TPanel; Label1: TLabel; Label2: TLabel; Timer1: TTimer; Button4: TButton; ColorDialog1: TColorDialog; FontDialog1: TFontDialog; Button6: TButton; Button7: TButton; ComboBox1: TComboBox; Panel4: TPanel; Edit2: TEdit; Edit3: TEdit; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Edit4: TEdit; Edit5: TEdit; Button8: TButton; Button5: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure TrackBar1Change(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button7Click(Sender: TObject); procedure Button6Click(Sender: TObject); procedure Button8Click(Sender: TObject); procedure Button5Click(Sender: TObject); private procedure zShowText; Procedure zBmpCreate; procedure zSetBmp; procedure zSetLineHeight; procedure zShowLine(sender :TObject); { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM} const bWidth=200; var currline, LineHeight:integer; sItem:TStringList; bmp:TBitMap; bRect,R1:TRect; iDc:HDC;procedure TForm1.Button1Click(Sender: TObject); begin OpenDialog1.Execute; Edit1.Text:=OpenDialog1.FileName; end;procedure TForm1.FormCreate(Sender: TObject); begin Form1.WindowState:=wsMaximized; Panel1.Top:=80; Panel1.Left:=96; Panel1.Height:=385; Panel1.Width:=433; Timer1.Enabled:=False; Label2.Caption:='100'; iDC:=GetDc(Panel1.handle); Currline:=0; end;procedure TForm1.zShowLine(sender :TObject); begin zShowText; end; procedure TForm1.Timer1Timer(Sender: TObject); begin zShowLine(self);//显示字符串 //bitblt 转移矩形图 (目标句柄,LS x,y,宽,高,源句柄,LS x,y,光栅运算符) BitBlt(iDc,0,0,Panel1.Width,Panel1.Height, Bmp.Canvas.Handle,0,Currline,srcCopy); Inc(Currline,1); if Currline>=bRect.Bottom-panel1.Height+100 then//循环条件? begin Timer1.Enabled:=False; Currline:=0; end; end; procedure TForm1.zShowText; var i:integer; ss:string; ReadFile:TextFile; begin AssignFile(ReadFile,Edit1.Text); Reset(ReadFile); i:=1; sItem:=TStringList.Create; with sItem do while not eof(ReadFile) do begin Readln(ReadFile,ss); add(ss); i:=i+1; end; CloseFile(ReadFile); zBmpCreate; sItem.Free;//释放串 end;procedure TForm1.zBmpCreate; //创建图片 var i,y:integer; //y begin if bmp<>nil then bmp.free; bmp:=TBitMap.Create; zSetBmp; R1.Right:=bRect.Right; R1.Bottom:=bRect.Bottom; y:=Panel1.Height-100; for i:=0 to sItem.Count-1 do // 从0到行数 循环显示图片 begin R1.Top:=y; R1.Bottom:=R1.Top+LineHeight; if Combobox1.Text='中间对齐' then //显示图片 DrawText(Bmp.Canvas.Handle,pChar(sItem[i]),-1,R1,Dt_Center or Dt_Top) else if Combobox1.Text='左对齐' then DrawText(Bmp.Canvas.Handle,pChar(sItem[i]),-1,R1,Dt_Left or Dt_Top) else if Combobox1.Text='右对齐'then DrawText(Bmp.Canvas.Handle,pChar(sItem[i]),-1,R1,Dt_Right or Dt_Top) else DrawText(Bmp.Canvas.Handle,pChar(sItem[i]),-1,R1,Dt_Center or Dt_Top); Inc(y,LineHeight); end; end;procedure TForm1.zSetBmp; begin zSetLineHeight; with bRect do //Rect 矩形坐标(左上x,左下y,右上x,右下y) begin Top:=0; Left:=0; Right:=Panel1.Width; Bottom:=LineHeight*sItem.Count+Height;//行高*行数+form高度 end; with Bmp do begin Height:=bRect.Bottom+100;//图片高度 Width:=bRect.Right; with Canvas do //canvas 画布 begin Font:=FontDialog1.Font; //Font:=self.Font;//form所设置的字体 Brush.Color:=ColorDialog1.Color; FillRect(bRect); Brush.Style:=bsClear; end; end; end;procedure TForm1.zSetLineHeight; {设置行间隔} var Metrics:TTextMetric; //设置字体 API begin GetTextMetrics(iDc,Metrics); LineHeight:=Metrics.tmHeight+Metrics.tmInternalLeading-Bmp.Canvas.Font.Height; end;procedure TForm1.Button2Click(Sender: TObject); begin if Edit1.Text='' then ShowMessage('请输入文件地址') else begin if Button2.Caption='开始' then Button2.Caption:='暂停' else Button2.Caption:='开始'; Timer1.Enabled:=not Timer1.Enabled; end; end;procedure TForm1.Button3Click(Sender: TObject); begin timer1.Enabled :=false; Currline:=0; Button2.Click; Button2.Caption:='暂停'; end;procedure TForm1.TrackBar1Change(Sender: TObject); begin Timer1.Interval:=TrackBar1.Position*5; Label2.Caption:=inttostr(Timer1.Interval); end;procedure TForm1.FormDestroy(Sender: TObject); begin if Bmp<>nil then Bmp.Free; end;procedure TForm1.Button4Click(Sender: TObject); begin close; end; procedure TForm1.Button7Click(Sender: TObject); begin FontDialog1.Execute; end;procedure TForm1.Button6Click(Sender: TObject); begin ColorDialog1.Execute; end;procedure TForm1.Button8Click(Sender: TObject); begin if ((strtoint(Edit2.Text)>=600) or (strtoint(Edit3.text)>=500) or ((strtoint(Edit5.Text)>=553) or (strtoint(Edit4.Text)>=630))) then showmessage('范围超界') else begin Panel1.Top:=strtoint(Edit2.text); Panel1.Left:=strtoint(Edit3.text); Panel1.Width:=strtoint(Edit4.text); Panel1.Height:=strtoint(Edit5.text); end;end;procedure TForm1.Button5Click(Sender: TObject); begin Panel1.Top:=0; Panel1.Left:=0; Panel1.Width:=Panel3.Width; Panel1.Height:=Panel3.Height; end;end.
至于渐隐渐显用一个循环来设值就可实现
至于源程序我会尽力发给你的,用flash做太浪费了,有点夸张
可以选择路径,速度,停留时间!unit aledtextclass;interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,stdctrls,fileoperdll,ledtextdialog,aledcommonfuc;
type
TTextMoveStyle=(msdown,msup);
{关键点结构}
{ keypoint=record
locate : tpoint; //关键点位置
waittime : integer; //在关键点停留时间
speed : integer; //从本点出发的速度
end;
}
{文字对象}
TLedText=class(TLabel)
public
code : string; //对象唯一标志符
starttime : integer; //开始演播时间
totalpath : integer; //关键点总数
path : array of keypoint; //关键点数组 oldpage : integer; //上次中断帧 stime : extended;
selected : boolean; //是否被选中
showpath : boolean; //是否显示路径 mousedown:boolean; //鼠标是否被按下
oldx,oldy:integer; newtext:boolean; //新建文本 times:integer;
published
properdlg:Tledtextproperdlg;
constructor Create(AOwner : TComponent); override;
destructor destroy; override; procedure WMSetFocus(var Message: TWMLBUTTONUP); message WM_LBUTTONUP;
procedure WMPaint(var Message: TWMPaint); message WM_Paint;
procedure WMLButtonDown(var Message: TWMLBUTTONDOWN); message WM_LBUTTONDOWN;
procedure WMMOUSEMOVE(var Message: TWMMOUSEMOVE); message WM_MOUSEMOVE; function savetostrings:tstrings;
procedure loadfromstrings(strs:tstrings); procedure setnamestr(str:string);
procedure setselected(sel:boolean);
function GetNameStr:string; public
{显示设置对话框}
function SetProperty:boolean; function GetStep(curpage: integer;var step:integer): integer;
{对象演示函数}
procedure play(curpage:integer;cas:tcanvas); end;function GetPoint(t:extended;s:integer;p1,p2:tpoint):tpoint;
function GetTwoPointLength(p1,p2:tpoint):extended;implementation
uses unit1,main;
{ TLedText }constructor TLedText.Create(AOwner: TComponent);
begin
inherited;
times:=0; showpath:=true;
end;destructor TLedText.destroy;
begin
inherited;end;
{
返回值:-1 表示不在该路径的内部
0 表示处于某点的等待状态
1 表示处于某段}
function TLedText.GetNameStr: string;
var
str:string;
sel:integer;
begin
getcontrolnamestr(name);
result:=str;
end;function TLedText.GetStep(curpage: integer;var step:integer): integer;
var
i:integer;
temptotaltime,t,totaltime:extended;
begin
{计算每段需要花费的时间}
if totalpath<=1 then
begin
result:=-1;
exit;
end;
totaltime:=starttime; for i:=0 to totalpath-2 do
begin
totaltime:=totaltime+path[i].waittime;
{如果在某点的等待时间内}
if curpage<=totaltime then
begin
result:=0;
exit;
end; {计算当前点到下一点需要的时间}
t:=gettwopointlength(path[i].locate,path[i+1].locate) /path[i].speed ;
temptotaltime:=totaltime;
totaltime:=totaltime+t;
{在两点中间时候}
if curpage<=totaltime then
begin
stime:=curpage*1.0-temptotaltime;
step:=i+1;
result:=1;
exit;
end;
end; result:=-1;
end;procedure TLedText.loadfromstrings(strs: tstrings);
var
i:integer;
str:string;
begin
if strs.count<6 then exit;
font.name:=strs[1];
font.height:=strtoint(strs[2]);
font.color:=strtoint(strs[3]);
left:=strtoint(strs[4]);
top:=strtoint(strs[5]);
if strs[6]='不透明' then transparent:=false
else transparent:=true;
caption:='';
str:='';
for i:=0 to strs.count-8 do
begin
if i=strs.count-8 then str:=str+strs[i+7]
else str:=str+strs[i+7]+#13+#10;
end;
caption:=str;
end;procedure TLedText.play(curpage:integer;cas:tcanvas);
var
i,step,ret:integer;
p:tpoint;
begin
{计算在时刻 curpage 时文字应处于的位置}
ret:=GetStep(curpage,step);
// form1.Label4.caption:=inttostr(step);
if (ret=-1) then
begin
left:=path[0].locate.x;
top:=path[0].locate.y;
end;
if ret<>1 then exit;
{获取文本位置}
if step=2 then
begin
end;
p:=GetPoint(stime,path[step-1].speed,path[step-1].locate,path[step].locate);
left:=p.x;
top:=p.y;
// form1.label1.caption:='x:'+inttostr(left);
// form1.label2.caption:='y:'+inttostr(top);
end;function TLedText.savetostrings: tstrings;
var
strs:tstrings;
i:integer;
str,tempstr:string;
begin
strs:=tstringlist.create;
strs.add('[文本]');
strs.Add(font.name);
strs.add(inttostr(font.height));
strs.add(inttostr(font.color));
strs.add(inttostr(left));
strs.add(inttostr(top));
if transparent then strs.add('透明')
else strs.add('不透明');
strs.add(caption);
result:=strs;
end;procedure TLedText.setnamestr(str: string);
var
tempstr:string;
begin
tempstr:=copy(name,1,4);
name:=tempstr+str;
end;function TLedText.SetProperty:boolean;
var
strs:tstrings;
sel,i,ret:integer;
str:string;
begin
application.CreateForm(Tledtextproperdlg,properdlg);
try
showpath:=false;
ledtextdialog.ledtransparent:=transparent;
properdlg.Memo1.font:=font;
properdlg.memo1.lines.clear; properdlg.editstart.text:=inttostr(starttime); if not newtext then
begin
properdlg.memo1.lines.add(Caption);
properdlg.Edit1.text:=getcontrolnamestr(name);
end; properdlg.edit1.text:=getcontrolnamestr(name);
{设置运动属性}
ledtextdialog.totalpath:=totalpath;
setlength(ledtextdialog.path,totalpath);
for i:=0 to totalpath-1 do
begin
ledtextdialog.path[i].locate:=path[i].locate;
ledtextdialog.path[i].waittime:=path[i].waittime;
ledtextdialog.path[i].speed:=path[i].speed;
end; unit1.showpath:=true;
if totalpath<>0 then
begin
properdlg.pathcombox.Items.clear;
for i:=0 to totalpath-1 do
begin
properdlg.pathcombox.Items.add(inttostr(i+1));
end;
end
else
begin
properdlg.pathcombox.items.clear;
properdlg.Editx.text:='';
properdlg.Edity.text:='';
properdlg.Editspeed.text:='';
properdlg.Editstay.text:='';
end; properdlg.newtext:=newtext;
properdlg.textname:=getcontrolnamestr(name); if newtext then
begin
properdlg.memo1.font.color:=clred;
end;
ret:=properdlg.showmodal;
str:=caption;
caption:='';
code:=properdlg.Edit1.text; if ret=mrok then result:=true else result:=false;
if ret<>mrok then
begin
caption:=str;
exit;
end;
strs:=properdlg.memo1.lines;
for i:=0 to strs.count-1 do
begin
if i<>strs.count-1 then
begin
caption:=caption+strs[i]+#13+#10;
end
else caption:=caption+strs[i];
end;
transparent:=properdlg.transbtn.checked;
font:=ledtextdialog.ledfont;
setcontrolnamestr(name,properdlg.edit1.text);
{设置开始时间} {设置路径属性}
totalpath:=ledtextdialog.totalpath;
setlength(path,totalpath);
for i:=0 to totalpath-1 do
begin
path[i].locate:=ledtextdialog.path[i].locate;
path[i].waittime:=ledtextdialog.path[i].waittime;
path[i].speed:=ledtextdialog.path[i].speed;
end;
showhint:=true;
hint:=code; finally
properdlg.Destroy;
showpath:=false;
form1.Invalidate;
selected:=true;
end;
end;procedure TLedText.setselected(sel: boolean);
var
str1,str2:string;
len:integer;
begin
name:=setcontrolselected(name,sel);
end;procedure TLedText.WMLButtonDown(var Message: TWMLBUTTONDOWN);
begin
inherited;
mousedown:=true;
oldx:=mouse.cursorpos.x;
oldy:=mouse.cursorpos.y;end;
procedure TLedText.WMMOUSEMOVE(var Message: TWMMOUSEMOVE);
var
p,p1:tpoint;
begin
inherited;
if mousedown then
begin
{将文本移动到指定位置}
p:=mouse.CursorPos;
left:=left+p.x-oldx;
top:=top+p.y-oldy;
oldx:=p.x;
oldy:=p.y;
end;
end;procedure TLedText.WMPaint(var Message: TWMPaint);
var
rect:trect;
r,g,b,i:integer;
begin
inherited;
{}
rect.left:=0;
rect.Top:=0;
rect.Right:=width;
rect.bottom:=height; if selected then
begin
canvas.Brush.Style:=bsclear;
canvas.Pen.Style:=psDot;
canvas.pen.color:=clwhite+10;
canvas.Rectangle(rect);
end;
showpath:=false;
if showpath then
begin
form1.canvas.moveto(path[0].locate.x,path[0].locate.y);
for i:=1 to totalpath-1 do
begin
if totalpath=0 then break;
{画路径线}
form1.canvas.Pen.color:=clred;
form1.Canvas.lineto(path[i].locate.x,path[i].locate.y);
form1.canvas.moveto(path[i].locate.x,path[i].locate.y);
end; end;end;procedure tledtext.WMSetFocus(var Message: TWMLBUTTONUP);
begin
inherited;
mousedown:=false;
selected:=not selected;
Invalidate;
{如果处于文字状态则修改}
setselected(selected);
if mainform.textbutton.down then
begin
newtext:=false;
setproperty;
end;
end;{通用函数}
{计算两点已经经历的时间的位置}
function GetPoint(t:extended;s:integer;p1,p2:tpoint):tpoint;
var
p:tpoint;
thr,temp,len,tempreal:real;
intx,floatx:integer;
thrthr:real;
begin
if (p2.x=p1.x) then
begin
end;
temp:=(p2.y-p1.y) / (p2.x-p1.x);
tempreal:=temp;
thr:=arctan(abs(temp));
thrthr:=thr;
if tempreal>0 then
begin
if p1.x>p2.x then temp:=p1.x-(t*s)*cos(thrthr)
else temp:=p1.x+(t*s)*cos(thrthr);
val(floattostr(temp),intx,floatx);
p.x:=intx;
if p1.y>p2.y then temp:=p1.y-(t*s)*sin(thrthr)
else temp:=p1.y+(t*s)*sin(thrthr); val(floattostr(temp),intx,floatx);
p.y:=intx;
end
else
begin
if p1.x>p2.x then temp:=p1.x-(t*s)*cos(thrthr)
else temp:=p1.x+(t*s)*cos(thrthr);
val(floattostr(temp),intx,floatx);
p.x:=intx;
if p1.y>p2.y then temp:=p1.y-(t*s)*sin(thrthr)
else temp:=p1.y+(t*s)*sin(thrthr); val(floattostr(temp),intx,floatx);
p.y:=intx; end; result:=p;end;
{计算当前时刻位于哪两点之中}
function GetTwoPointLength(p1,p2:tpoint):extended;
var
x:extended;
begin
x:=sqr(p2.y-p1.y)+sqr(p2.x-p1.x); result:=sqrt(x);
end;end.
Rxlib下载:
我列出几个可能的网站
http://www.chinaasp.com/delphi/
http://202.103.176.81/frun/bruce_zhao/
http://delphi.yesite.com/
http://www.wapsec.com.cn/delphi/
字符消隐可以通过函数得到窗体背景颜色值和字体颜色值之间的差再等分成若干分(视程序和字体颜色值而定),然后加一个TTimer组件,在其中把颜色值逐个赋予TLabel1.font.color,就可以实现消隐了。
至于飞入几行后向上移动,只需加一个简单的判断语句,应该不难的。
其他的呢,我也不太清楚了。
答得不对,别笑喔
你的方法是对的,但是效果很差劲:闪烁得很厉害!
To jjdelphi(星辰):
实在不想写代码,上次给你的代码原理就是那个样子了。一头雾水的代码我没有测试,也许可以,你看看吧。
主要是利用 Canvas.TextOut(X,Y,'String') 方法,不断的
改变它的 X 或 Y 的值,实现左右或上下移动。
要改变字体,直接改变 Canvas.Font 就可以。
你要做的效果可以参照这种方法。下面的代码运行通过,
你可以看一下它运行时的效果。
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if Height-i<0 then i:=0; // i 是一个全局的整型变量;
Timer1.Interval :=100;
Canvas.TextOut(100,Height - i,'AAA');
if i=Round(Height/2) then
Timer1.Interval:=2000; // 当字符在中央时,让它停留2秒钟;
i:= i + 1; // 改变 i 的值实现字符上移;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
i:=0;
Canvas.Brush.Color :=color;
// 用 Form1 的背景色填充画布,要不然画布是白色。
Canvas.FillRect(Rect(Left,Top,Left+Width,Top+Height));
end;
让文件的每一行一行一行的上升,该怎样实现循环?
Canvas.TextOut(x, y,'aaa') 中的 x, y 就可以。
比如在他前面加上一句 if (height-i)=100 then i:=height-100;
这样 height-i 的值就不会再变。字符串也就不会动了。
其实我上面代码的第一句 if Height-i<0 then i:=0;就是
实现循环的。
也就是说,和你的要求不一样,但是你可以稍微修改一下就可以了,有代码的哦!
如果需要,请mailto:[email protected]
字符串 'BBB' 开始从下出来,当 'BBB' 也移到中央时,
停止两秒钟,接着 'AAA' 开始向上隐去,当 'AAA' 看不到
时, 'BBB' 开始向上隐去,当 'BBB' 也看不到时,回到初始
状态,进行循环。
你可以运行这段代码看看效果,读懂了代码,相信你的问题就
可以解决了。我的 E_mail : [email protected]
oicq: 22309797
procedure TForm1.Timer1Timer(Sender: TObject);
begin
timer1.Interval :=10;
if flag=false then // 向上拉出
if i<(round(height/2)) then
begin
canvas.TextOut(100,height-i,'AAA');
I:=I+1;
end
else
if j<(Round(height/2)) then
begin
Canvas.TextOut(200,height-j,'BBB');
j:=J+1;
end
else
begin
timer1.Interval :=2000;
flag:=true;
end ;if flag=true then // 向上隐去
if i<height+15 then // 加15是字符串的高度
begin
Canvas.TextOut(100,height-i,'AAA');
i:=i+1;
end
else
if j<Height+15 then
begin
Canvas.TextOut(200,height-j,'BBB');
j:=j+1;
end
else
begin
flag:=false;
i:=0;
j:=0;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
// i , j, flag 是全局变量;
i:=0;
j:=0;
flag:=false;
Canvas.Brush.Color :=color;
Canvas.FillRect(Rect(0, 0, Width, Height));
end;
还不能实现从一侧飞入的效果
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ComCtrls, ColorGrd, RxCombos;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
OpenDialog1: TOpenDialog;
Button2: TButton;
Button3: TButton;
TrackBar1: TTrackBar;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Label1: TLabel;
Label2: TLabel;
Timer1: TTimer;
Button4: TButton;
ColorDialog1: TColorDialog;
FontDialog1: TFontDialog;
Button6: TButton;
Button7: TButton;
ComboBox1: TComboBox;
Panel4: TPanel;
Edit2: TEdit;
Edit3: TEdit;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Edit4: TEdit;
Edit5: TEdit;
Button8: TButton;
Button5: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
procedure zShowText;
Procedure zBmpCreate;
procedure zSetBmp;
procedure zSetLineHeight;
procedure zShowLine(sender :TObject);
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}
const
bWidth=200;
var
currline, LineHeight:integer;
sItem:TStringList;
bmp:TBitMap;
bRect,R1:TRect;
iDc:HDC;procedure TForm1.Button1Click(Sender: TObject);
begin
OpenDialog1.Execute;
Edit1.Text:=OpenDialog1.FileName;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.WindowState:=wsMaximized;
Panel1.Top:=80;
Panel1.Left:=96;
Panel1.Height:=385;
Panel1.Width:=433;
Timer1.Enabled:=False;
Label2.Caption:='100';
iDC:=GetDc(Panel1.handle);
Currline:=0;
end;procedure TForm1.zShowLine(sender :TObject);
begin
zShowText;
end; procedure TForm1.Timer1Timer(Sender: TObject);
begin
zShowLine(self);//显示字符串
//bitblt 转移矩形图 (目标句柄,LS x,y,宽,高,源句柄,LS x,y,光栅运算符)
BitBlt(iDc,0,0,Panel1.Width,Panel1.Height,
Bmp.Canvas.Handle,0,Currline,srcCopy);
Inc(Currline,1);
if Currline>=bRect.Bottom-panel1.Height+100 then//循环条件?
begin
Timer1.Enabled:=False;
Currline:=0;
end;
end;
procedure TForm1.zShowText;
var
i:integer;
ss:string;
ReadFile:TextFile;
begin
AssignFile(ReadFile,Edit1.Text);
Reset(ReadFile);
i:=1;
sItem:=TStringList.Create;
with sItem do
while not eof(ReadFile) do
begin
Readln(ReadFile,ss);
add(ss);
i:=i+1;
end;
CloseFile(ReadFile);
zBmpCreate;
sItem.Free;//释放串
end;procedure TForm1.zBmpCreate; //创建图片
var
i,y:integer; //y
begin
if bmp<>nil then bmp.free;
bmp:=TBitMap.Create;
zSetBmp;
R1.Right:=bRect.Right;
R1.Bottom:=bRect.Bottom;
y:=Panel1.Height-100;
for i:=0 to sItem.Count-1 do // 从0到行数 循环显示图片
begin
R1.Top:=y;
R1.Bottom:=R1.Top+LineHeight;
if Combobox1.Text='中间对齐' then //显示图片
DrawText(Bmp.Canvas.Handle,pChar(sItem[i]),-1,R1,Dt_Center or Dt_Top)
else
if Combobox1.Text='左对齐' then
DrawText(Bmp.Canvas.Handle,pChar(sItem[i]),-1,R1,Dt_Left or Dt_Top)
else
if Combobox1.Text='右对齐'then
DrawText(Bmp.Canvas.Handle,pChar(sItem[i]),-1,R1,Dt_Right or Dt_Top)
else
DrawText(Bmp.Canvas.Handle,pChar(sItem[i]),-1,R1,Dt_Center or Dt_Top);
Inc(y,LineHeight);
end;
end;procedure TForm1.zSetBmp;
begin
zSetLineHeight;
with bRect do //Rect 矩形坐标(左上x,左下y,右上x,右下y)
begin
Top:=0;
Left:=0;
Right:=Panel1.Width;
Bottom:=LineHeight*sItem.Count+Height;//行高*行数+form高度
end;
with Bmp do
begin
Height:=bRect.Bottom+100;//图片高度
Width:=bRect.Right;
with Canvas do //canvas 画布
begin
Font:=FontDialog1.Font;
//Font:=self.Font;//form所设置的字体
Brush.Color:=ColorDialog1.Color;
FillRect(bRect);
Brush.Style:=bsClear;
end;
end;
end;procedure TForm1.zSetLineHeight;
{设置行间隔}
var
Metrics:TTextMetric; //设置字体 API
begin
GetTextMetrics(iDc,Metrics);
LineHeight:=Metrics.tmHeight+Metrics.tmInternalLeading-Bmp.Canvas.Font.Height;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
if Edit1.Text='' then ShowMessage('请输入文件地址')
else
begin
if Button2.Caption='开始' then Button2.Caption:='暂停'
else Button2.Caption:='开始';
Timer1.Enabled:=not Timer1.Enabled;
end;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
timer1.Enabled :=false;
Currline:=0;
Button2.Click;
Button2.Caption:='暂停';
end;procedure TForm1.TrackBar1Change(Sender: TObject);
begin
Timer1.Interval:=TrackBar1.Position*5;
Label2.Caption:=inttostr(Timer1.Interval);
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
if Bmp<>nil then Bmp.Free;
end;procedure TForm1.Button4Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
FontDialog1.Execute;
end;procedure TForm1.Button6Click(Sender: TObject);
begin
ColorDialog1.Execute;
end;procedure TForm1.Button8Click(Sender: TObject);
begin
if ((strtoint(Edit2.Text)>=600) or (strtoint(Edit3.text)>=500) or ((strtoint(Edit5.Text)>=553) or (strtoint(Edit4.Text)>=630)))
then showmessage('范围超界')
else
begin
Panel1.Top:=strtoint(Edit2.text);
Panel1.Left:=strtoint(Edit3.text);
Panel1.Width:=strtoint(Edit4.text);
Panel1.Height:=strtoint(Edit5.text);
end;end;procedure TForm1.Button5Click(Sender: TObject);
begin
Panel1.Top:=0;
Panel1.Left:=0;
Panel1.Width:=Panel3.Width;
Panel1.Height:=Panel3.Height;
end;end.
恭喜jjDelphi~~~~~~~~
自己做的收获大的多~~~~~~~~~~~~~~
告诉你一个好东东:
http://kingron.myetang.com/soft/db.zip
快去哦~~~~~~~~~看了绝对不后悔~
能帮我看看关于VFP的问题吗?
我倒……
不好意思,我不会
这个控件如何设置对齐方式