首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

VB中怎么让ToolTip弹出的提示为图片

2012-12-16 
VB中如何让ToolTip弹出的提示为图片?当鼠标移动到Label上面弹出图片提示![最优解释]楼主看看这个。新建一个

VB中如何让ToolTip弹出的提示为图片?
当鼠标移动到Label上面弹出图片提示!
[最优解释]
楼主看看这个。

新建一个标准 EXE工程,添加 Label1、Timer1
我是把窗口标题栏画了一块上去。
你要画别的,自己修改一下吧。你看着办。

Option Explicit

Private Declare Function GetDesktopWindow Lib "user32.dll" () As Long
Private Declare Function IsWindowVisible Lib "user32.dll" (ByVal hWnd&) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function GetWindow Lib "user32.dll" (ByVal hWnd As Long, _
                     ByVal wCmd As Long) As Long
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" ( _
                     ByVal hWnd As Long, ByVal lpClassName As String, _
                     ByVal nMaxCount As Long) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hWwnd As Long, _
                     ByVal X As Long, ByVal Y As Long, _
                     ByVal nWidth As Long, ByVal nHeight As Long, _
                     ByVal bRepaint As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, _
                     ByVal X As Long, ByVal Y As Long, _
                     ByVal nWidth As Long, ByVal nHeight As Long, _
                     ByVal hSrcDC As Long, ByVal xSrc As Long, _
                     ByVal ySrc As Long, ByVal dwRop As Long) As Long

Private Type RECT
    Left    As Long
    Top     As Long
    Right   As Long
    Bottom  As Long
End Type

Private Sub DrawImgInTooltip(lWnd As Long)
      Dim hWndTool As Long, strClass As String


      Dim hToolDC As Long, hFormDC As Long
      Dim uWinRECT As RECT
   hWndTool = GetWindow(lWnd, 5)
   If (hWndTool) Then
      If (IsWindowVisible(hWndTool) = 0) Then Exit Sub
      strClass = String$(20, vbNullChar)
      Call GetClassName(hWndTool, strClass, 18)
      If (InStr(strClass, "VBBubble")) Then
         Call GetWindowRect(hWndTool, uWinRECT)
         Call MoveWindow(hWndTool, uWinRECT.Left, uWinRECT.Top, 66, 20, -1)
         hToolDC = GetWindowDC(hWndTool)
         hFormDC = GetWindowDC(hWnd)
         Call BitBlt(hToolDC, 0, 0, 66, 20, hFormDC, 4, 6, vbSrcCopy)
         Call ReleaseDC(hWndTool, hWndTool)
         Call ReleaseDC(hWnd, hFormDC)
      End If
   End If
End Sub

Private Sub Form_Load()
   Timer1.Enabled = False
   Timer1.Interval = 10
   Label1.ToolTipText = " "   ' 一个空格
End Sub

Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
   Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
   Timer1.Enabled = False
   Call DrawImgInTooltip(GetDesktopWindow)
End Sub



[其他解释]
ToolTip有些困难,看可以考虑使用picturebox来实现
[其他解释]
自己用Image控件或picturebox控件来实现吧, 在label控件的mousemove事件中指定显示的位置即可.
[其他解释]
向各位老师大神学习;好好学习天天向上

热点排行