您的位置:首页 > 编程语言 > Delphi

一个从右到左,文字循环平滑滚动的例子(Delphi7测试通过)

2008-05-15 15:12 706 查看
procedure TForm2.Button1Click(Sender: TObject);
var
oldRect, rzPanelRect: TRect;
oldBitmap: TBitmap;
position, I, TxtWidth, CWidth, iPosition: Integer;
fText: string;
pWidth, pHeight: integer;
begin
{
一个从右到左,文字循环平滑滚动的例子。
2008-05-15。by Heavy.
}
position := 0;
iPosition := 0;
fText := '战胜灾难,众志成城!';
pWidth := RzPanel1.Width;
pHeight := RzPanel1.Height;

oldBitmap := TBitmap.Create;

oldBitmap.Width := pWidth;
oldBitmap.Height := pHeight;

oldBitmap.Canvas.Brush.Color := clActiveCaption;
//填充背景色
oldBitmap.Canvas.FillRect(Rect(0,0,oldBitmap.Width,oldBitmap.Height));
oldBitmap.Canvas.Font.Color := clWhite;
oldBitmap.Canvas.Font.Size := 14;
oldBitmap.Canvas.TextOut(0, 10, fText);
TxtWidth := oldBitmap.Canvas.TextWidth(fText);

while Position >= -pWidth - TxtWidth do
begin
if Position <= -pWidth then
RzPanel1.Canvas.Draw(2 * pWidth + Position, 0, oldBitmap);
RzPanel1.Canvas.Draw(pWidth + Position, 0, oldBitmap);
sleep(50);
Application.ProcessMessages;
if Position = -pWidth - TxtWidth then
Position := -TxtWidth;
Dec(Position);
end;
end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: