教程中国
PHOTOSHOP CS9.0中文版 MAYA 8.5 FOR WINDOWS Corel Painter v9.0 Flash MX2004 中文版 Illustrator cs2 中文版
VC++6.0含sp6 中英文版 VB6.0 +sp6 简体中文版 Borland Delphi 7汉化版 MSDN for vb6.0中文版 Visual Studio 2005简体
教程中国下属 文件存储共享专家BIBIDU.COM 提供大型软件,教材,源码,电影,音乐,图书等下载 更多精品请点此进入
  您目前所在位置: 教程中国 >> 编程基地 >> VB >> 将长ListBox项显示为ToolTip RSS订阅
将长ListBox项显示为ToolTip
教程(视频,书籍)下载:  ASP.NET AutoCAD 数据库 C# ASP java photoshop 网页设计 delphi 3dmax Flash C++ VB 张孝祥 实例   更多请进入BIBIDU搜索
IT搜索引擎   
Showing long ListBox entries as a ToolTip
By Matt Vandenbush, matt_vandenbush@whbrady.com
Sometimes the data you want to display in a list is too long for the size of ListBox you can use. When this happens, you can use some simple code to display the ListBox entries as ToolTips when the mouse passes over the ListBox.

First, start a new VB project and add a ListBox to the default form. Then declare the SendMessage API call and the constant (LB_ITEMFROMPOINT) needed for the operation:

Option Explicit

注释:Declare the API function call.
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
注释: Add API constant
Private Const LB_ITEMFROMPOINT = &H1A9

Next, add some code to the form load event to fill the ListBox with data:

Private Sub Form_Load()
注释:
注释: load some items in the list box
With List1
.AddItem "Michael Clifford Amundsen"
.AddItem "Walter P.K. Smithworthy, III"
.AddItem "Alicia May Sue McPherson-Pennington"
End With
注释:
End Sub

Finally, in the MouseMove event of the ListBox, put the following code:

Private Sub List1_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
注释:
注释: present related tip message
注释:
Dim lXPoint As Long
Dim lYPoint As Long
Dim lIndex As Long
注释:
If Button = 0 Then 注释: if no button was pressed
  lXPoint = CLng(X / Screen.TwipsPerPixelX)
  lYPoint = CLng(Y / Screen.TwipsPerPixelY)
  注释:
  With List1
    注释: get selected item from list
    lIndex = SendMessage(.hwnd, _
    LB_ITEMFROMPOINT, _
    0, _
    ByVal ((lYPoint * 65536) + lXPoint))
    注释: show tip or clear last one
    If (lIndex >= 0) And (lIndex <= .ListCount) Then
      .ToolTipText = .List(lIndex)
    Else
      .ToolTipText = ""
    End If
  End With 注释:(List1)
End If 注释:(button=0)
注释:
End Sub 

来源:upschool.cn
作者:
关键字:
发表日期:2006-12-20 17:27:26

网页显示有限 阅读全文请下载本文完整版WORD文档

上一篇:用VB绘制抛物线动画曲线   下一篇:用别名选项防止API崩溃


2009-1-9 4:49:11
本文的相类似文章
在学习中进步 在进步中成长 教程中国相随您的成长之路
华腾联合科技股份有限公司版权所有
广告联系:Rosibo@163.com