| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1027 人关注过本帖
标题:改进的ListBox中的字符串超长显示的解决方法(支持dirListBox,FileListBox)
只看楼主 加入收藏
jiashie
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:237
专家分:999
注 册:2009-4-30
结帖率:100%
收藏
 问题点数:0 回复次数:1 
改进的ListBox中的字符串超长显示的解决方法(支持dirListBox,FileListBox)
程序代码:
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 Function ShowListTips(ByRef objList As Control, Button As Integer, Shift As Integer, X As Single, Y As Single) As Long

    On Error GoTo errHandler

    '//! 支持dirListBox、FileListBox,ListBox
    Dim lXPoint As Long, lYPoint As Long
    Dim lIndex  As Long, n As Long

    If Button = 0 Then 'if no button was pressed
        lXPoint = CLng(X / Screen.TwipsPerPixelX)
        lYPoint = CLng(Y / Screen.TwipsPerPixelY)

        With objList
            'get selected item from list
            lIndex = SendMessage(.hwnd, LB_ITEMFROMPOINT, 0, ByVal ((lYPoint * 65536) + lXPoint))

            'get the hidden item count if the objList is a dirListbox
            'If TypeOf objList Is DirListBox Then
            If TypeName(objList) = "DirListBox" Then
                n = UBound(Split(objList.List(0), "\"))
            End If

            'show tip or clear last one
            If (lIndex >= 0) And (lIndex <= .ListCount+n) Then
                .ToolTipText = .List(lIndex-n)
            Else
                .ToolTipText = ""
            End If

        End With

    End If

    Exit Function

errHandler:
    Debug.Print Err.Number, Err.Description
End Function
'调用示例:
'在ListBox的MouseMove事件中 
'Call ShowListTips(控件名称,Button,Shift,X,Y)


[ 本帖最后由 jiashie 于 2010-6-29 10:24 编辑 ]
搜索更多相关主题的帖子: 字符串 
2010-06-29 10:12
wei855198
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:5
帖 子:228
专家分:944
注 册:2009-4-24
收藏
得分:0 
顶!

护肤小店 http://mina2010.
靓装小店 http://liangliyizu2010.
2010-06-30 10:31
快速回复:改进的ListBox中的字符串超长显示的解决方法(支持dirListBox,FileLis ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030155 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved