Delphi中自画TStatusBar面板中的文字颜色背景以及图片

转自 http://www.delphitop.com/html/kongjian/351.html

首先定义:

procedure TStatusForm.FormCreate(Sender: TObject) ;

begin

StatusBar1.Panels[0].Style := psOwnerDraw;

StatusBar1.Panels[1].Style := psOwnerDraw;

end;

自画事件:

procedure TStatusForm.StatusBar1DrawPanel(

StatusBar: TStatusBar;

Panel: TStatusPanel;

const Rect: TRect) ;

begin

with StatusBar.Canvas do

begin

case Panel.Index of

0: //fist panel

begin

Brush.Color := clRed;

Font.Color := clNavy;

Font.Style := [fsBold];

end;

1: //second panel

begin

Brush.Color := clYellow;

Font.Color := clTeal;

Font.Style := [fsItalic];

end;

end;

//Panel background color

FillRect(Rect) ;

//Panel Text

TextRect(Rect,2 + ImageList1.Width + Rect.Left, 2 + Rect.Top,Panel.Text) ;

end;

//draw graphics

ImageList1.Draw(StatusBar1.Canvas, Rect.Left, Rect.Top, Panel.Index) ;

end;