How can I draw a progress bar or gif animation in a grid cell ?
Thanks !
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.
精彩评论