<b>ListBox编程两例</b>[VC/C++编程]
本文“<b>ListBox编程两例</b>[VC/C++编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
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) ;
}
以上是“<b>ListBox编程两例</b>[VC/C++编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |