【例子介绍】仿任务管理器cpu占用显示
【相关图片】
【源码结构】
procedure TForm1.DrawPL(Shower:TImage); //主要源码
var
Bit: TBitmap;
i: Integer;
PW,PH: Integer;
YValue:Integer;
begin
//偏移量计算
Inc(X);
if X = GridSpace div MoveStep then
X := 0;
//初始化画布(双缓冲)
Bit := TBitmap.Create;
try
PW := Shower.Width;
PH := Shower.Height;
Bit.Width := PW;
Bit.Height := PH;
//初始化网格竖线X坐标数组长度为宽/间隔 1
SetLength(GridXPArr,PW div GridSpace 1);
with Bit.Canvas do
begin
Brush.Color := clBlack;
Brush.Style := bsSolid;
Rectangle(0,0,PW,PH);
Pen.Color := $00408000;
//画网格,根据偏移量实现动态效果
for i := 0 to PW div GridSpace 1 do
begin
GridXPArr[i] := GridSpace * i - X * MoveStep;
MoveTo(GridXPArr[i],0);
LineTo(GridXPArr[i],PH);
end;
for i := 0 to PH div GridSpace do
begin
MoveTo(0,GridSpace * i);
LineTo(PW,GridSpace * i);
end;
//画折线
Pen.Color := clLime;
YValue := 0;
//如果队列中有新的Y坐标点,则输出
if YPQueue.Count > 0 then
begin
PYValue := YPQueue.Pop;
YValue := PYValue^;
Dispose(PYValue);
end;
//画笔移动到起点位置
MoveTo(0,PH);
//每执行一次函数,Y坐标向前移动一位,并连线各个点
for i := 0 to Length(PointLst) - 2 do
begin
PointLst[i].Y := PointLst[i 1].Y;
LineTo(PointLst[i 1].X,PointLst[i 1].Y);
end;
//按比例更新最后一位坐标点
PointLst[Length(PointLst)-1].X := PW;
PointLst[Length(PointLst)-1].Y := PH - (YValue * PH div MaxY);
//打印信息(可根据需要调整显示位置和内容)
Brush.Style:=bsClear;
Font.Color:=clYellow;
TextOut(10,10,'数值:' inttostr(YValue));
end;
Shower.Canvas.Draw(0,0,Bit);
finally
Bit.Free;
end;
end;


评论