如果只是位置居中显示的简单,只需要把每个Panel的Alignment属性设为taCenter就可以了,
如果要分色稍复杂点:
procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
Var R:TRect;
begin
StatusBar.Canvas.FillRect(Rect);
//填充背景.
R:=Rect;
case Panel.Index of
0:StatusBar.Canvas.Font.Color:=clRed;
1:StatusBar.Canvas.Font.Color:=clGreen;
end;
//分别定义不同的颜色.
DrawText(StatusBar.Canvas.Handle,PChar(Panel.Text),Length(Panel.Text),R,DT_CENTER or DT_VCENTER or DT_SINGLELINE);
//居中绘制.
end;
procedure TForm1.FormCreate(Sender: TObject);
Var i:Integer;
begin
For i:=0 to StatusBar1.Panels.Count-1 do
StatusBar1.Panels.Style:=psOwnerDraw;
//每一个子面板都需要自绘.
end;