void __fastcall TForm1::FormCreate(TObject *Sender)
{
ListBmp = new Graphics::TBitmap;
ListBmp->LoadFromFile(ExtractFilePath(ParamStr(0)) + "fantasy.bmp");
FillBmp = new Graphics::TBitmap;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State)
{
String tekst = ListBox1->Items->Strings[Index];
unsigned short x = (ListBox1->ItemHeight - ListBox1->Canvas->TextHeight(tekst))/2 - 1;
int segment = Index - ListBox1->TopIndex;
if(State.Contains(odSelected))
{
ListBox1->Canvas->Brush->Color = clYellow;
ListBox1->Canvas->Font->Color = clBlue;
ListBox1->Canvas->Brush->Style = bsSolid;
Frame3D(ListBox1->Canvas, Rect, (TColor)0x00C6E7FF, (TColor)0x000086FF, x/2);
}
else
ListBox1->Canvas->Brush->Style = bsClear;
FillBitmap(FillBmp, ListBmp, ListBox1);
TRect ARect;
ARect.left = Rect.left;
ARect.top = segment * ListBox1->ItemHeight;
ARect.right = Rect.right;
ARect.bottom = (segment * ListBox1->ItemHeight) + ListBox1->ItemHeight;
ListBox1->Canvas->CopyRect(Rect, FillBmp->Canvas, ARect);
ListBox1->Canvas->FillRect(Rect);
ListBox1->Canvas->TextOut(Rect.Left + x, Rect.Top + x, ListBox1->Items->Strings[Index]);
Timer1->Enabled = false;
Timer1->Enabled = true;
}
//---------------------------------------------------------------------------
void TForm1::FillBitmap(Graphics::TBitmap *FillBmp, Graphics::TBitmap *ListBmp, TListBox *ListBox)
{
FillBmp->Width = ListBox->Width;
FillBmp->Height = ListBox->Items->Count * ListBox->ItemHeight;
FillBmp->Canvas->Brush->Bitmap = ListBmp;
FillBmp->Canvas->FillRect(Rect(0, 0, FillBmp->Width, FillBmp->Height));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Timer1->Enabled = false;
if ( iLastTopIndex != ListBox1->TopIndex )
{
ListBox1->Repaint();
iLastTopIndex = ListBox1->TopIndex;
}
}
//---------------------------------------------------------------------------