网格进度条或动画

时间:2011-03-01 01:04:21

标签: delphi

如何在网格单元格中绘制进度条或gif动画?

谢谢!

1 个答案:

答案 0 :(得分:4)

以下是我用于在状态栏面板中绘制进度条的一些代码:

  R := Rect;
  R.Right := MulDiv(Width, FProgressPercent, 100);
  inc(R.Right, R.Left);
  (* We prefer to draw our inline progress bar using the prevailing theme.  However, the theme API
     uses the wrong colour on XP so we only do this for Vista / Server 2008 and later. *)
  if (Win32MajorVersion>=6) and ThemeServices.ThemesEnabled then begin
    Details.Element := teProgress;
    Details.Part := PP_FILL;
    Details.State := PBFS_NORMAL;
    ThemeServices.DrawElement(Canvas.Handle, Details, R);
  end else begin
    Canvas.Brush.Color := clHighlight;
    Canvas.Brush.Style := bsSolid;
    Canvas.FillRect(R);
  end;

此代码在OnDrawPanel事件处理程序中运行,但您希望对网格使用类似OnDrawCell事件的内容。 Rect是我的代码中状态栏面板的客户区域,您需要代码的整个网格单元格。

我还通过在上面的代码之后运行此代码在顶部绘制一个百分比文本。

  Text := Format('%d%%', [FProgressPercent]);
  Size := Canvas.TextExtent(Text);
  Left := Rect.Left+(Width-Size.cx) div 2;
  Top := Rect.Top+(Height-Size.cy) div 2;
  Canvas.Brush.Style := bsClear;
  Canvas.Font.Color := clHighlightText;
  Canvas.Font.Style := [fsBold];
  Canvas.TextRect(Rect, Left, Top, Text);

与您想要的完全不同,但希望这些想法能够贯穿始终。