实现StatusBar的Flat风格
只要你有一台电脑或者手机,都能关注图老师为大家精心推荐的实现StatusBar的Flat风格,手机电脑控们准备好了吗?一起看过来吧!
把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;
效果还不错吧