起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 369|回复: 8

【搞定】DataTreeList进度条实现问题**

[复制链接]
发表于 2007-5-28 09:17:02 | 显示全部楼层 |阅读模式
版主,按照
http://bbs.justep.com/forum.php?mod=viewthread&tid=9329

帖子上的内容在DataTreeList的OnCustomDrawCell事件中调用DoCustomDrawPercentCell方法,但是运行该功能时所有的字段都显示为了进度条状态(参考图示)[/url]
是传递的参数有问题还是其他的原因呢?请教版主
调用时:
  DoCustomDrawPercentCell(Sender, ACanvas, ARect, ANode, AColumn, ASelected, AFocused,
    ANewItemRow, DataSetBroker1.DataSet.FieldByName('FPLANPERCENT').AsInteger,
    DataSetBroker1.DataSet.FieldByName('FFACTPERCENT').AsInteger, AText, AColor, AFont, AAlignment, ADone);
其中'FPLANPERCENT'为计划百分比,'FFACTPERCENT'为实际百分比。

无标题.gif

5.07 KB, 下载次数: 257

回复

使用道具 举报

 楼主| 发表于 2007-5-28 15:50:04 | 显示全部楼层
版主可以明白我的需求吗,给个反馈好吗?
回复 支持 反对

使用道具 举报

发表于 2007-5-28 17:57:01 | 显示全部楼层
{
调用:
  TPlanGraphicLib.DoCustomDrawPercentCell(Sender, ACanvas, ARect, ANode, AColumn, ASelected, AFocused, ANewItemRow,
    VarToInt(ANode.Values[IndexOfTreeColumn(lDataTreeList, 'FPLANPERCENT')]),
    VarToInt(ANode.Values[IndexOfTreeColumn(lDataTreeList, 'FFACTPERCENT')]),
    AText, AColor, AFont, AAlignment, ADone);
}


//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;
回复 支持 反对

使用道具 举报

发表于 2007-5-28 17:58:54 | 显示全部楼层
在OnCustomDrawCell事件中,当然你要判断是哪个字段了,只有进度字段才画进度条,其他字段就不要画了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-5-29 08:56:38 | 显示全部楼层
版主,我按照3楼的方法调用还是不行呀
(我调用时是这么写的:
DoCustomDrawPercentCell(Sender, ACanvas, ARect, ANode, AColumn, ASelected, AFocused,
    ANewItemRow, VarToInt(ANode.Values[IndexOfTreeColumn(DataTreeList1, 'FPLANPERCENT')]),
    VarToInt(ANode.Values[IndexOfTreeColumn(DataTreeList1, 'FFACTPERCENT')]), AText, AColor, AFont, AAlignment, ADone);
)版主在四楼说要判断一下进度字段,这个进度字段怎么判断呢?
回复 支持 反对

使用道具 举报

发表于 2007-5-29 09:34:56 | 显示全部楼层
不需要判断哪个字段,而是新建一个TDatagridImageColumn字段,然后在这个字段的事件中调用!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-5-29 09:44:08 | 显示全部楼层
版主能给个代码示例吗?
回复 支持 反对

使用道具 举报

发表于 2007-5-29 21:54:53 | 显示全部楼层
在设计期间就可以加这个字段,不需要再写代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-5-30 09:01:53 | 显示全部楼层
ok,问题搞定,谢谢版主,结帖:)
回复 支持 反对

使用道具 举报

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

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2025-1-11 04:19 , Processed in 0.040228 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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