岁数大了,QQ也不闪了,微信也不响了,电话也不来了,但是图老师依旧坚持为大家推荐最精彩的内容,下面为大家精心准备的ListBox编程两例,希望大家看完后能赶快学习起来。
【 tulaoshi.com - 编程语言 】
1。 为ListBox添加水平方向的滚动条
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)SendMessage (ListBox1-Handle,LB_SETHORIZONTALEXTENT,ListBox1-Width + 32,0) ;
2。 为Listbox添加图标
首先需要设置Listbox的Style属性为lbOwnerDrawVariable;
const margin = 2 ; // Margin around each bitmap(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)
//---------------------------------------------------------------------------
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) ;
}
来源:http://www.tulaoshi.com/n/20160219/1612470.html