Two examples of ListBox programming

Source: Internet
Author: User

1. To add a horizontal scroll bar to the listbox

SendMessage (Listbox1->handle,lb_sethorizontalextent,listbox1->width + 32,0);

2. Add an icon to a ListBox

First you need to set the Style property of the listbox to 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)
{
//fill background.
Listbox1->canvas->fillrect (Rect);
//Draw an image.
Imagelist1->draw (Listbox1->canvas, rect.left + margin, rect.top + margin, Index);
//Draw the text.
String Text = listbox1->items->strings [Index]; The
//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);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.