unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ComCtrls;
type
TForm1 = class(TForm)
StatusBar1: TStatusBar;
Timer1: TTimer;
procedure StatusBar1DrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel;
const Rect: TRect);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
f,w:integer;
//記錄文字加入的起始點和文字的寬度
tmp_rect:trect;
//記錄文字顯示區域
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel;
const Rect: TRect);
begin
//記錄要顯示文字的區域值
tmp_rect.Left:=rect.Left;
tmp_rect.Top:=rect.Top;
tmp_rect.Right:=rect.Right;
tmp_rect.Bottom:=rect.Bottom;
f:=tmp_rect.Right;
//得到文字顯示起始點
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
with statusbar1.canvasdo
begin
//顯示文字?
fillrect(tmp_rect);
font.Color:=clblack;
w:=textwidth('欢迎光临!');
pen.Style:=psclear;
rectangle(tmp_rect.Left,tmp_rect.Top,tmp_rect.Right,tmp_rect.Bottom);
textout(f,tmp_rect.Top,'欢迎光临!');
end;
//計算文字顯示起始點
if f>-w then
f:=f-30
else
f:=tmp_rect.Right;
end;
end.