使用ToolTip来解决超长文字的显示问题是不错的方案,下面给出了例子的代码。
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_ITEMFROMPOINT = &H1A9
Private Sub Form_Load()
    Dim i As Integer
    For i = 0 To 5
        List1.AddItem "ListItem字符串超长超长超长超长超长咯    " & i
    Next
End Sub
Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim lParam As Long
    Dim lResult As Long
    lParam = (CInt(Y / Screen.TwipsPerPixelY) * 2 ^ 16) + CInt(X / Screen.TwipsPerPixelX)
    lResult = SendMessage(List1.hwnd, LB_ITEMFROMPOINT, 0, ByVal lParam)
   
    If lResult < 0 Or lResult > 32767 Then
字符串长度过长        List1.ToolTipText = ""
        Exit Sub
    End If
   
    Dim nIndex As Integer
    nIndex = CInt(lResult)
    List1.ToolTipText = List1.List(nIndex)
End Sub
Win2000 + VB6 中调试通过

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。