资源预览内容
第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
亲,该文档总共3页全部预览完了,如果喜欢就下载吧!
资源描述
VB中处理长列表框项的两种方法Lib “user32“ Alias “SendMessageA“ _(ByVal hwnd As Long, ByVal wMsgAs Long, ByVal wParam As Long, _lParam As Any) As Long Private Const LB_ITEMFROMPOINT = &H1A9 编写列表框的鼠标移动大事代码如下: Private Sub List1_MouseMove(Button As Integer,Shift As Integer, _X As Single, Y As Single) Dim lXPoint As Long Dim lYPoint As LongDim lIndex As LongIf Button = 0 ThenlXPoint = CLng(X / Screen.TwipsPerPixelX)lYPoint = CLng(Y / Screen.TwipsPerPixelY) With List1 获得当前条目的索引号lIndex = SendMessage(.hwnd, LB_ITEMFROMPOINT, 0, _ByVal (lYPoint * 65536) + lXPoint)If (lIndex = 0) And (lIndex .Width Then.ToolTipText = .List(lIndex)Else.ToolTipText = “End IfEnd IfEnd WithEnd If End Sub 在Form_Load大事中为列表框添加几个条目供验证使用: Private Sub Form_Load() With List1 .AddItem “智能列表框Listbox“.AddItem “这是一个长条目信息,将鼠标移到其上,你就能看到完整信息“End With End Sub 其次种方法的思路和第一种是根本类似的,但直接使用字体的大小属性来推断,不需要使用API函数,看一下下面的代码就明白了。可以使用下面的代码来替换上面的列表框鼠标移动大事代码:Private Sub List1_MouseMove(Button As Integer, Shift As Integer, _X As Single, Y As Single)Dim Ypos As Integer, iOldFontSize As IntegeriOldFontSize = Me.Font.SizeMe.Font.Size = List1.Font.SizeYpos = Y Me.TextHeight(“Xyz“) + List1.TopIndexMe.Font.Size = iOldFontSizeIf Ypos List1.ListCount ThenList1.ToolTipText = List1.List(Ypos)ElseList1.ToolTipText = “End IfEnd Sub 程序运行环境:中文VB 5.0专业版,中文WIN95。
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号