|
-
Mar 28th, 2000, 12:39 AM
#1
Thread Starter
Hyperactive Member
I have heard that it's possible to have the tools tips function of a control to show the textual contents of the control over which it hovers. For instance if the cursor hovers over the txt box for LastName the tooltips would show the last name when it kicks in. How can this be done?
What I want to do actually, if possible is to hover over a cell in a DataGrid and have the tool tip dispay the contents of that particular cell.
Thanks,
Rev. Michael L. Burns
-
Mar 28th, 2000, 02:13 AM
#2
Addicted Member
I got this from this web page:
http://msdn.microsoft.com/vbasic/technical/pasttips.asp
This is the part you are interested in:
For the Week of Febuary 2, 1998
Showing long ListBox entries as a ToolTip
By Matt Vandenbush, [email protected]
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
Top of Page
--------------------------------------------------------------------------------
Last Updated: 3/27/00
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|