当前位置:主页>Delphi教程>文章内容
实现StatusBar的Flat风格
来源: 作者: 发布时间:2007-04-29  
具有Flat风格的StatusBar  效果见右图,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;

  效果还不错吧

 
上一篇:来自SVG的灵感   下一篇:SQLServer中按某字段排列名次
 
  相关文章
·来自SVG的灵感
·SQLServer中按某字段排列名次
·动态SQL语句在SQLServer中非固定行的转
·Delphi使用方法
·入手自制软件背单词
·在Delphi中如何把数据库中的记录引到wo
·SQLServer中一个多用户自动生成编号的
·用Delphi4.0直接控制Word97
·让你的DBGridEh的Column自动适应宽度
·Delphi数据集过滤技巧
·Delphi的拨号连接类
·Delphi与Word之间的融合技术
 
【关闭窗口】
推荐本站资源
最新文章