实现StatusBar的Flat风格
2006-02-04 13:51:39 来源:WEB开发网核心提示:效果见右图,OfficeXP里就是这样的风格,实现StatusBar的Flat风格,其实实现很简单,不必专门在网上找别人控件,下面是StutasBar的OnDrawPanel事件代码:PRocedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar; Panel:
效果见右图,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;
效果还不错吧
把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;
效果还不错吧
更多精彩
赞助商链接