Get row position in mouse pointer in ListBox

xiaoxiao2021-03-06  56

The ListBox control does not provide this attribute value to be called. Here I wrote a complete presentation for your reference.

Create a new project, plus a Listbox and a Label on the Form1 form. Paste the following procedure in the form code and run it.

Option expedition

Private Declare Function SendMessage Lib "User32" Alias ​​"SendMessagea" (Byval WMSG As Long, Byval WParam As Long, LParam As Any) As longprivate const lb_ItemFromPoint = & H1A9

PRIVATE SUB FORM_LOAD () DIM I as Integer for i = 1 To 5 List1.AddItem Trim (Str (I)) Nextend Sub

Private Sub List1_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single) Dim LstPOS As Long Dim XX As Long Dim YY As Long XX = CLng (X / Screen.TwipsPerPixelX) YY = CLng (Y / Screen. TWIPSPERPIELY) LSTPOS = SendMessage (List1.hwnd, LB_ItemFromPoint, 0, Byval ((YY * 65536) XX)) IF LSTPOS

'-------------------------------------------' Please indicate the source 'author: Don just fine' E-mail: tanaya@163.com '------------------------------------- --------

转载请注明原文地址:https://www.9cbs.com/read-114803.html

New Post(0)