说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

ListBox项的控制-VB资料

HTML文档下载 WORD文档下载 PDF文档下载
ListBox项的控制-VB资料
ListView和TreeView可以通过HitTest来实现对各项的控制,那么ListBox有没 有方法方法实现对其项的控制呢?答案上肯定的。
下面的例子实现的ListBox各项的自动选择,就象弹出ComboBox的下拉框,然后 移动鼠标时,光条跟着移动。
>>步骤1----建立新工程,在窗体上放置ListBox控件。
>>步骤2----编写如下代码:

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()
With List1
.AddItem "程序编制:小马哥"
.AddItem "Mailto:Schunte@sina.com"
.AddItem "Http://MaJiFeng.Top263.net"
End With
End Sub

Private Sub List1_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)

Dim lXPoint As Long
Dim lYPoint As Long
Dim lIndex As Long
lXPoint = 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 <= .ListCount) Then
.Selected(lIndex) = True
Else
.Selected(lIndex) = False
End If
End With
End Sub

>>步骤3----编译运行,鼠标在ListBox上移动,看看是不是自动选择。
备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘