ListBox编程两例

王朝other·作者佚名  2008-06-01
窄屏简体版  字體: |||超大  

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) ;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航