发送消息LB_ITEMFROMPOINT获取位置
方法一 发消息
void __fastcall TForm2::ListBox1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
int idx;
idx = SendMessage(ListBox1->Handle, LB_ITEMFROMPOINT, 0, MAKELPARAM(X,Y)) ;
ListBox1->Hint = ListBox1->Items->Strings[idx];
ListBox1->ItemIndex = idx;
BitBtn2->Top = ListBox1->Top+ ListBox1->ItemHeight*(idx);
}
方法二 ItemAtPos方法
void __fastcall TForm2::ListBox1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
int idx;
TPoint p(X,Y);
idx = ListBox1->ItemAtPos(p,true);
ListBox1->Hint = ListBox1->Items->Strings[idx];
ListBox1->ItemIndex = idx;
BitBtn2->Top = ListBox1->Top+ ListBox1->ItemHeight*(idx);
}