设为首页设为首页
 添加收藏添加收藏
 进入音乐版音 乐 版
  汉南在线程序设计VB程序

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上移动,看看是不是自动选择。


来源:互联网
阅读:592
日期:2005-11-21

【 双击滚屏 】 【 收藏 】 【 打印 】 【 关闭 】 【 字体: 】 
上一篇:VB中的时间处理问题
下一篇:防止用户编辑文本框控件中的内

  >> 相关文章
 
  ·VB中的时间处理问题
  ·恢复回收站中的文件
  ·处理加了密码的MDB文件
  ·比较两个文件
  ·VB中自制文件搜索器
  ·VB编程的好帮手--资源文件
  ·用VB设计聚焦框程序
  ·用EXCEL组件简化VB编程
授权使用:汉南在线 http://www.hzwz.net/(2008-2009)   
Copyright (c) 2002-2007 汉南在线. All Rights Reserved . 
经营许可证:陕ICP备05000109号 Powered by:汉南在线