我现在在VB中使用树控件要求鼠标移动到相应的节点上时,要使用ToolTip提示节点的内容,当节点内容超过了80个字符时,ToolTip只能提示前80个字符,请问怎么修改ToolTip提示内容的长度大小带提示完整的内容,急!!!!!
解决方案 »
- VSprinter打印vsflexgrid问题
- 一个关于sqlserver数据库加密码的问题。帮忙解释一下。
- 如何绘制长期的数据曲线
- 在线等待,在sqlserver,将''插入到一个日期字段,发现日期字段的值为'1900-01-01',我想让值为空,如何解决呢
- 又是一个菜问题:如何限制vb中form地大小
- 怎样动态改变Image控件显示的图片?
- 求救!关于在vb程序中创建ODBC数据源(SQL Server),很急!
- Vb项目实训设计怎么做啊?
- 怎样用vb编写自动加入日志文件到数据库
- micrisift comm control6.0如何使用?
- 在开发好的一个VB窗体中,软件不让做任何修改,一旦修改再次加载时提示不能加载控件 QCSZ!
- VB怎样更改XML中的属性值
别用自带的ToolTip,自己模拟一个
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As LongPrivate Const LVM_FIRST = &H1000
Private Const LVM_SUBITEMHITTEST = (LVM_FIRST + 57)
Private Const LVM_GETSUBITEMRECT = (LVM_FIRST + 56)
Private Const LVM_GETITEMRECT = (LVM_FIRST + 14)
Private Const LVIR_BOUNDS = 0
Private Const LVM_GETSTRINGWIDTHA = (LVM_FIRST + 17)
Private Const LVM_GETSELECTEDCOUNT = (LVM_FIRST + 50)
Private Const LVM_DELETEALLITEMS = (LVM_FIRST + 9)Private Type POINTAPI
x As Long
y As Long
End TypePrivate Type LVHITTESTINFO
pt As POINTAPI
Flags As Long
iItem As Long
iSubItem As Long
End TypePrivate Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End TypePrivate lblTT As TextBox
Private lblToolText As LabelPrivate xPos As Long
Private yPos As Long
Private lvHti As LVHITTESTINFO'获取subitem索引
Public Function GetLvwIndex(LvwList As ListView, ptIndex As POINTAPI)
GetCursorPos lvHti.pt
ScreenToClient LvwList.hwnd, lvHti.pt
Call SendMessage(LvwList.hwnd, LVM_SUBITEMHITTEST, 0, lvHti.pt)
ptIndex.x = lvHti.iSubItem
ptIndex.y = lvHti.iItem
End Function'工具提示
Public Sub ShowToolTip(Lvw As ListView)
On Error Resume Next
Dim LvwItem As ListItem
Dim i As Long, iSub As Long
Dim lpPt As POINTAPI, lpPt2 As POINTAPI
Dim lpRect As RECT
Dim lWidth As Long
Dim lHeight As Long
Dim MaxWidth As Long
Dim CltWidth As Long
Dim LvwRect As RECT
Dim TTLeft As Long
Static TTTop As Long
Dim ptOffsetX As Long
Dim ptOffsetY As Long
Dim TTPt As POINTAPI
Static bFlag As Boolean
Static oldPT As POINTAPI
Call GetLvwIndex(Lvw, lpPt)
If lpPt.x < 0 Or lpPt.y < 0 Then Exit Sub
'******************************************
Set lblTT = Lvw.Parent.Controls.Add("VB.TextBox", "lblTT")
Set lblToolText = Lvw.Parent.Controls.Add("VB.Label", "lblToolText")
lblTT.Locked = True
lblTT.BackColor = vbInfoBackground
lblTT.Appearance = 0
lblTT.TabStop = False
lblToolText.BackColor = vbInfoBackground
lblToolText.AutoSize = True
lblToolText.BorderStyle = 0
'********************************************
ptOffsetX = 240
ptOffsetY = 360
MaxWidth = Lvw.Parent.ScaleWidth - 120
With Lvw.Parent
GetCursorPos lpPt2
If lpPt2.x <> oldPT.x Or lpPt2.y <> oldPT.y Then
If xPos <> lpPt.x Or yPos <> lpPt.y Then
'Debug.Print "tooltiptext"
Set LvwItem = Lvw.ListItems(lpPt.y + 1)
lpRect.Left = LVIR_BOUNDS
lpRect.Top = lpPt.x
bFlag = False
If lpPt.x > 0 Then
Call SendMessage(Lvw.hwnd, LVM_GETSUBITEMRECT, lpPt.y, lpRect) '矩形
lWidth = SendMessage(Lvw.hwnd, LVM_GETSTRINGWIDTHA, 0, ByVal LvwItem.SubItems(lpPt.x)) '显示需宽度
Else
Call SendMessage(Lvw.hwnd, LVM_GETITEMRECT, lpPt.y, lpRect) '矩形
lpRect.Right = Lvw.ColumnHeaders(1).Width / 15
lWidth = SendMessage(Lvw.hwnd, LVM_GETSTRINGWIDTHA, 0, ByVal LvwItem.Text) '显示需宽度
End If
If lpRect.Left < 0 Then
bFlag = True
Else
GetClientRect Lvw.hwnd, LvwRect
CltWidth = LvwRect.Right
If lpRect.Left + lWidth > CltWidth Then
bFlag = True
ElseIf lpRect.Right - lpRect.Left - 12 < lWidth Then
bFlag = True
End If
End If
If bFlag Then
lblToolText.Font.Name = Lvw.Font.Name
lblToolText.Font.Size = Lvw.Font.Size
If lpPt.x > 0 Then
lblToolText.Caption = LvwItem.SubItems(lpPt.x)
Else
lblToolText.Caption = LvwItem.Text
End If
lblTT.Font.Name = lblToolText.Font.Name
lblTT.Font.Size = lblToolText.Font.Size
lblTT.Font.Bold = False
lblTT.Font.Italic = False
lblTT.Text = lblToolText.Caption
lblTT.Width = lblToolText.Width + 120
lblTT.Height = lblToolText.Height + 120
'Debug.Print .lblTT.Text
lblToolText.Caption = ""
TTPt.x = lpRect.Right
TTPt.y = lpRect.Bottom
ClientToScreen Lvw.hwnd, TTPt
ScreenToClient .hwnd, TTPt
'Debug.Print TTPt.x, TTPt.y
TTTop = (TTPt.y + 16) * 15
End If
xPos = lpPt.x
yPos = lpPt.y
End If
'显示工具提示
If bFlag Then
ScreenToClient .hwnd, lpPt2
'TTTop = lpPt2.y * 15 + ptOffsetY
If lblTT.Width = MaxWidth Then
lblTT.Top = TTTop
ElseIf lblTT.Width < MaxWidth Then
TTLeft = lpPt2.x * 15 + ptOffsetX
If TTLeft < 60 Then
TTLeft = 60
ElseIf TTLeft > MaxWidth - lblTT.Width Then
TTLeft = MaxWidth - lblTT.Width
End If
lblTT.Move TTLeft, TTTop
'Debug.Print TTLeft
Else
lHeight = lblTT.Width \ MaxWidth
If lHeight = lblTT.Width / MaxWidth Then
lblTT.Height = lHeight * lblTT.Height
Else
lblTT.Height = (lHeight + 1) * lblTT.Height
End If
lblTT.Width = MaxWidth
lblTT.Move 60, TTTop, lblTT.Width, lblTT.Height
'Debug.Print "超出"
End If
If lblTT.Visible = False Then
lblTT.Visible = True
lblTT.ZOrder
End If
Else
If lblTT.Visible Then
lblTT.Visible = False
lblTT.Text = ""
End If
End If
oldPT = lpPt2
End If
End With
Set LvwItem = Nothing
End Sub'清除工具提示
Sub ClearLvwToolTip()
On Error Resume Next
If lblTT Is Nothing Then Exit Sub
lblTT.Visible = False
lblTT.Text = ""
xPos = -1: yPos = -1
End Sub