网格进度条或动画 [英] Grid progressbar or animation

查看:154
本文介绍了网格进度条或动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



谢谢!

解决方案

这里有一些我在状态栏面板中绘制进度条的代码:

  R:= Rect; 
R.Right:= MulDiv(Width,FProgressPercent,100);
inc(R.Right,R.Left);
(*我们更喜欢使用主流的主题绘制我们的内联进度条,但主题API
在XP上使用错误的颜色,所以我们只为Vista / Server 2008及更高版本执行此操作。*)
if(Win32MajorVersion> = 6)和ThemeServices.ThemesEnabled然后开始
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);
结束

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



/ p>

 文本:=格式('%d %%',[FProgressPercent]); 
大小:= Canvas.TextExtent(Text);
左:= Rect.Left +(Width-Size.cx)div 2;
顶部:= 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);

与您想做的不完全一样,但希望这些想法将持续下去。 >

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.

这篇关于网格进度条或动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆