ItemRect (C++)
Description
This example uses a list box on a form. When you click one of the items in the list box, a beep occurs if the mouse is in the first half of the item. A similar technique can be used to detect "hot" regions in an owner-draw list box.
Code
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
ListBox1->Items->Add("Hello");
ListBox1->Items->Add("New");
ListBox1->Items->Add("World");
}
void __fastcall TForm1::ListBox1MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
TRect ItemBounds;
if (Button == mbLeft)
{
ItemBounds = ListBox1->ItemRect(ListBox1->ItemIndex);
if (Y > ItemBounds.Top &&
Y < ItemBounds.Bottom &&
X > ItemBounds.Left &&
X < (ItemBounds.Left + ItemBounds.Right)/2)
MessageBeep(0);
}
}
Uses
- Vcl.StdCtrls.TCustomListBox.ItemRect ( fr | de | ja )