1。 為ListBox添加水平方向的滾動條
SendMessage (ListBox1->Handle,LB_SETHORIZONTALEXTENT,ListBox1->Width + 32,0) ;
2。 為Listbox添加圖標
首先需要設置Listbox的Style屬性為lbOwnerDrawVariable;
const margin = 2 ; // Margin around each bitmap
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox1MeasureItem(TWinControl *Control, int Index,
int &Height)
{
Height = ImageList1->Height + margin * 2 ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int Index,
TRect &Rect, TOwnerDrawState State)
{
// 填充背景.
ListBox1->Canvas->FillRect (Rect) ;
// 畫出圖像.
ImageList1->Draw (ListBox1->Canvas, Rect.Left + margin, Rect.Top + margin, Index) ;
// 畫出文字.
String text = ListBox1->Items->Strings [Index] ;
// Center the text vertically in relation to the bitmap.
int off = (Rect.Bottom - Rect.Top - ListBox1->Canvas->TextHeight (text)) / 2 ;
ListBox1->Canvas->TextOut (Rect.Left + ImageList1->Width + 2 * margin,
Rect.Top + off,text) ;
}