//把 PaintBox 放到 ScrollBox 里
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
randomize(); //初始化随机数
ScrollBox1->DoubleBuffered=true;
}
//---------------------------------------------------------------------------
int dx=0,xs[1000]; //最多显示1000个点
int dy=0,ys[1000];
int nn=0;
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
if(nn<1000)
{
xs[nn]=(dx+=random(10));
ys[nn]=(dy+=random(10));
nn++;
if(dx>PaintBox1->Width)PaintBox1->Width=dx;
if(dy>PaintBox1->Height)PaintBox1->Height=dy;
PaintBox1->Invalidate();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBox1Paint(TObject *Sender)
{
TRect rc(0,0,PaintBox1->Width,PaintBox1->Height);
PaintBox1->Canvas->Brush->Color=clWhite;
PaintBox1->Canvas->FillRect(rc);
PaintBox1->Canvas->MoveTo(xs[0],ys[0]);
for(int i=1; i PaintBox1->Canvas->LineTo(xs[i],ys[i]);
}
//---------------------------------------------------------------------------
--------------------next---------------------
阅读(1334) | 评论(0) | 转发(0) |