在窗体上放入以Timer控件,在控件的Timer事件中写入
var
BrushPt:TPoint;
BrushHandl,OldBrush:HBRUSH;
FormDC:HDC;
BrushOffset:Integer;
begin
BrushOffset:=0;
FormDC:=GetDC(Form1.Handle);
Inc(BrushOffset);
BrushHandl:=CreateHatchBrush(HS_DIAGCROSS,clRed);
SetBrushOrgEx(FormDC,BrushOffset,BrushOffset,nil);
//设置画刷为网格形式
OldBrush:=Select Object(FormDC,BrushHandl);
GetBrush(FormDC,BrushPt); //获得当前画刷
if BrushPt.X>7 then
begin
BrushOffset:=0;
SetBrushShorgEx(FormDC,BrushOffset,BrushOffset,nil);
end;
Rectangle(FormDC,OldBrush);
DeleteObject(BrushHandl);
ReleaseDC(Form1.Handle,FormDC)
end;
end;