效果見上圖,OfficeXP裡就是這樣的風格,其實實現很簡單,不必專門在網上找別人控件。
把StatusBar的SimplePanel設為False,點擊Panels添加StatusPanel,把所有StatusPanel的Bevel設為pbNone、Style設為psOwnerDraw因為我們要自己繪制Flat風格。下面是StutasBar的OnDrawPanel事件代碼:
procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
var
uAlign: UINT;
R: TRect;
begin
case Panel.Alignment of
taLeftJustify : uAlign := DT_LEFT;
taCenter : uAlign := DT_CENTER;
taRightJustify : uAlign := DT_RIGHT;
end;
uAlign := uAlign or DT_VCENTER;
with StatusBar.Canvas do begin
Pen.Color := $E1E1E1;
Brush.Color := StatusBar.Color;
Rectangle(Rect);
Brush.Style := bsClear;
R.Left := Rect.Left + 1;
R.Right := Rect.Right - 1;
R.Top := Rect.Top + 1;
R.Bottom := Rect.Bottom - 1;
DrawText(StatusBar.Canvas.Handle, PChar(Panel.Text), -1, R, uAlign);
end;
end;
右圖的界面中,第一StatusPanel應該是自動調整大小的,所以還得處理StatusBar.OnResize事件,代碼如下:
procedure TForm1.StatusBar1Resize(Sender: TObject);
var
i, w: integer;
begin
w := StatusBar1.Width;
for i:=1 to StatusBar1.Panels.Count-1 do
w := w - StatusBar1.Panels[i].Width;
StatusBar1.Panels[0].Width := w;
end;
效果還不錯吧