起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 1367|回复: 0

DataGrid进度条实现过程

[复制链接]
发表于 2006-7-25 11:36:13 | 显示全部楼层 |阅读模式
//DataGrid进度条实现过程:
static procedure TProjManageLib.DoCustomDrawPercentCell(Sender: TObject;
  ACanvas: TCanvas; ARect: TRect;
  ANode: TTreeListNode; AColumn: TTreeListColumn;
  ASelected, AFocused, ANewItemRow: Boolean;
  APlanPercent, AFactPercent: Integer;
  var AText: string;
  var AColor: Integer; AFont: TFont;
  var AAlignment: TAlignment;
  var ADone: Boolean);
var
  I: Integer;
  lColorList: Array of Integer;
  lPercentText: string;
begin
  if ADone then Exit;

  ACanvas.Brush.Style := TBrushStyle.bsClear;
  DoDrawBrushColor(Sender, ACanvas.Brush, ANode, AColor, ASelected, AFocused);

  ACanvas.Pen.Color := ACanvas.Brush.Color;
  ACanvas.Rectangle(ARect);
  ACanvas.Pen.Color := $000000;
  ACanvas.Rectangle(ARect.Left + 1, ARect.Top + 1, ARect.Right - 1, ARect.Bottom - 1);

  if APlanPercent > AFactPercent then
    lColorList := [$1C1C53, $282877, $323295, $3A3AAC, $3E3EBA, $4040BF]
  else
    lColorList := [$006100, $008500, $009300, $00aa00, $00c800, $00ec00];

  for I := 0 to 5 do
  begin
    ACanvas.Pen.Color := lColorList[I];
    ACanvas.MoveTo(ARect.Left + 2, ARect.Top + 2 + I);
    ACanvas.LineTo(ARect.Right - 2, ARect.Top + 2 + I);
    ACanvas.MoveTo(ARect.Left + 2, ARect.Bottom - 3 - I);
    ACanvas.LineTo(ARect.Right - 2, ARect.Bottom - 3 - I);
  end;

  ACanvas.Brush.Style := TBrushStyle.bsSolid;
  ACanvas.Brush.Color := $FF8080;
  ACanvas.Pen.Color := $FF8080;
  ACanvas.Rectangle(ARect.Left + 2, ARect.Top + 4, ((ARect.Right - 2) - (ARect.Left + 2)) * APlanPercent div 100 + (ARect.Left + 2), ARect.Top + 7);
  ACanvas.Brush.Color := $800040;
  ACanvas.Pen.Color := $800040;
  ACanvas.Rectangle(ARect.Left + 2, ARect.Top + 9, ((ARect.Right - 2) - (ARect.Left + 2)) * AFactPercent div 100 + (ARect.Left + 2), ARect.Top + 12);
  ACanvas.Brush.Style := TBrushStyle.bsClear;

  lPercentText := SysUtils.Format('%d%%', [AFactPercent]);
  ACanvas.Font.Size := 9;
  ACanvas.Font.Color := $ffffff;
  ACanvas.TextOut(
    (ARect.Right - ARect.Left) div 2 + ARect.Left - ACanvas.TextWidth(lPercentText) div 2,
    ARect.Top + 2, lPercentText);

  ADone := True;
end;

static procedure TProjManageLib.DoDrawBrushColor(Sender: TObject;
  ABrush: TBrush; ANode: TTreeListNode; AColor: Integer;
  ASelected, AFocused: Boolean);
begin
  if ANode.Owner.Focused and ASelected then
    ABrush.Color := Graphics.clHighlight
  else if ANode.HasChildren or (ASelected and not AFocused) then
  begin
    if AColor = Graphics.clWhite then
      ABrush.Color := Graphics.clBtnFace
    else
      ABrush.Color := AColor;
  end
  else
    ABrush.Color := AColor;
end;

static function TProjManageLib.VarToInt(V: Variant): Integer;
begin
  if not (Variants.VarIsNUll(V) or Variants.VarIsEmpty(V) or Variants.VarIsClear(V)) and
    Variants.VarIsType(V, [$0002, $0003, $0010, $0011, $0012, $0013]) then
    Result := Integer(V) else
    Result := 0;
end;

static function TProjManageLib.IndexOfTreeColumn(ADataTreeList: TDataTreeList;
  const FieldName: string): Integer;
var
  I: Integer;
begin
  for I := 0 to ADataTreeList.ColumnCount - 1 do
    if (SysUtils.AnsiCompareText(ADataTreeList.Columns[I].FieldName, FieldName) = 0) or
      ((ADataTreeList.Columns[I].FieldName = '') and
       (SysUtils.AnsiCompareText(ADataTreeList.Columns[I].Name, FieldName) = 0)) then
    begin
      Result := I;
      Exit;
    end;
  Result := -1;
end;

static function TProjManageLib.IndexOfGridColumn(ADataGrid: TDataGrid;
  const FieldName: string): Integer;
var
  I: Integer;
begin
  for I := 0 to ADataGrid.ColumnCount - 1 do
  begin
    if (SysUtils.AnsiCompareText(ADataGrid.Columns[I].ColumnDef.FieldName, FieldName) = 0) or
      ((ADataGrid.Columns[I].ColumnDef.FieldName = '') and
       (SysUtils.AnsiCompareText(ADataGrid.Columns[I].Name, FieldName) = 0)) then
    begin
      Result := I;
      Exit;
    end;
  end;
  Result := -1;
end;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2024-12-22 18:29 , Processed in 0.038771 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表