środa, 12 stycznia 2022

this - example component TListBox - C++ Builder

 







TForm1 *Form1;
int number=4;
TListBox *newList[4];
TColor colors[4]={clBlue,clYellow,clGreen,clRed};
TColor penCol[4]={clWhite,clBlack,clYellow,clBlue};
AnsiString mFont[4]={"Arial","Times","Alchemist","GE Glob"};
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
 srand(time(NULL));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
 int i,mLeft,mTop,mWidth,mHeight;
 mWidth=120;mHeight=240;
 mTop=Form1->Height/4;
 mWidth=Form1->Width/4;
 AnsiString a="ListBoxA";
 for(i=0;i<number;i++)
 {
  newList[i]=new TListBox(this);
  newList[i]->Name=a+IntToStr(i+1);
  newList[i]->Width=mWidth;
  newList[i]->Height=mHeight;
  newList[i]->Left=((i+1)*mWidth)-mWidth;
  newList[i]->Top=mTop;
  newList[i]->Brush->Color=colors[i];
  newList[i]->Font->Color=penCol[i];
  newList[i]->Font->Size=15;
  newList[i]->Font->Name=mFont[i];
  newList[i]->Parent=this;




 }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
 int i;
 for(i=0;i<number;i++)
 {
  delete newList[i];
 }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
 int i,j;
  for(i=0;i<number*2;i++)
  {
   for(j=0;j<number;j++)
   {
     newList[j]->Items->Add(IntToStr(i+1)+") - Random(10) - "+IntToStr(1+rand()%10));
   }
  }

}




Brak komentarzy:

Prześlij komentarz