发布网友 发布时间:2024-07-03 09:33
共2个回答
热心网友 时间:2024-07-14 09:01
(1)
Const LB_GETITEMHEIGHT = &H1A1
HeightLst = SendMessage(List1.hWnd, LB_GETITEMHEIGHT, 0, 0) '得到List每项的高度,单位为像素
(2)函数获取当前鼠标所在List的哪一项
Friend Function ListIndex(ByVal lY As Single, ByVal ListCount As Integer) As Integer
Dim i%
'当前项为最顶部显示的第一项 + 鼠标所在的第n项
i = List1.TopIndex + (lY \ Screen.TwipsPerPixelY \ HeightLst)
If i > ListCount - 1 Or ListCount = 0 Then i = -1
ListIndex = i
End Function
(3)在List的MouseMove事件检查文本长度,若超过控件宽度,设置ToolTip值
Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lIndex% '鼠标当前指向的索引
Static preIndex& '保留前次索引
lIndex = ListIndex(Y, List1.ListCount)
If lIndex >= 0 Then
Dim TextSize As POINTAPI
Dim lstRec As RECT
'获取list窗口位置
GetWindowRect List1.hWnd, lstRec
'获取当前文本长度
GetTextExtentPoint32 Me.hdc, List1.List(lIndex), LenB(List1.List(lIndex)), TextSize
'如果文本太长不够显示就出现tip
If TextSize.X >= List1.Width Then
List1.TooltipText=cstr(Now)
Else
List1.TooltipText=""
End If
End If
End Sub
热心网友 时间:2024-07-14 09:05
用API可以改变其宽度