Grid progressbar or animation

后端 未结 1 917
眼角桃花
眼角桃花 2021-01-03 19:19

How can I draw a progress bar or gif animation in a grid cell ?

Thanks !

相关标签:
1条回答
  • 2021-01-03 19:45

    Here's some code I use to draw a progress bar in a status bar panel:

      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;
    

    This code runs in an OnDrawPanel event handler, but you'd want to use something like the OnDrawCell event for a grid. Rect is the client area of the status bar panel in my code, you'd want the entire grid cell for your code.

    I also draw a percentage text over the top by running this code after the code above.

      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);
    

    Not exactly the same as you want to do, but hopefully the ideas will carry across.

    0 讨论(0)
提交回复
热议问题