I have added three images to ImageList..I want to show tooltip....On listview item...

Public Class Form2

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListView1.View = View.LargeIcon
        ListView1.LargeImageList = ImageList1
        For lcount As Integer = 1 To 3
            ListView1.Items.Add(lcount.ToString, lcount - 1)
        Next

    End Sub

    Private Sub ListView1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.MouseLeave
        Dim a As New ToolTip
        a.SetToolTip(ListView1, "")
    End Sub

    Private Sub ListView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseMove
        Dim thisItem As ListViewItem = ListView1.GetItemAt(e.X, e.Y)

        Dim a As New ToolTip

        If Not thisItem Is Nothing Then

            a.SetToolTip(ListView1, thisItem.Text)

        Else

            a.SetToolTip(ListView1, "")

        End If

    End Sub
End Class

Mine code is working fine..But probs is that..as i hover the mouse suppose over the first image tooltip is shown..Now when i hover the mouse on second image..first image tooltip is still there..I want first tooltip to be disappeared...How to do that..can somebody tell me help me??/

Dani AI

Generated

The "tooltip sticking" is happening because a new ToolTip object is created on every MouseMove/Leave, so the old one keeps showing until it times out. Reuse a single ToolTip instance and hide it when the pointer leaves or when the hovered item changes.

' Form-level fields
Private ReadOnly tip As New ToolTip() With {.InitialDelay = 200, .ReshowDelay = 50, .AutoPopDelay = 3000}
Private last As ListViewItem = Nothing

Private Sub ListView1_MouseMove(sender As Object, e As MouseEventArgs) Handles ListView1.MouseMove
    Dim hit = ListView1.GetItemAt(e.X, e.Y)
    If Not Object.ReferenceEquals(hit, last) Then
        If hit Is Nothing Then
            tip.Hide(ListView1)
        Else
            tip.Show(hit.Text, ListView1, e.Location + New Size(16, 16), 3000)
        End If
        last = hit
    End If
End Sub

Private Sub ListView1_MouseLeave(sender As Object, e As EventArgs) Handles ListView1.MouseLeave
    tip.Hide(ListView1)
End Sub

If you just need text tooltips per item, ’s suggestion is the simplest and is the built-in path: turn on ShowItemToolTips and set each item’s ToolTipText. The framework manages timing and hiding for you. (learn.microsoft.com)

Want image + text? Do not rely on ShowItemToolTips for that. Use your ToolTip component, set OwnerDraw = True, handle Draw/Popup, and show the tip yourself (e.g., in MouseMove as above). Those events fire only for the ToolTip control that is actually displaying the popup. (learn.microsoft.com)

For ’s "room moves to the corner" issue: that is usually ListView auto-arranging/sorting. Keep items where you put them by disabling AutoArrange and any sorting, then set positions explicitly (works in LargeIcon/SmallIcon views).

ListView1.View = View.LargeIcon
ListView1.AutoArrange = False
ListView1.Sorting = SortOrder.None
someItem.Position = New Point(30, 30)

See AutoArrange and the Position property for details. (learn.microsoft.com)

Recommended Answers

All 7 Replies

Enabled the ListView1.ShowItemToolTips = True.

ListView1.View = View.LargeIcon
       ListView1.ShowItemToolTips = True
       For lcount As Integer = 1 To 3
            ListView1.Items.Add(lcount.ToString, lcount - 1).ToolTipText = "Item" & lcount
        Next

Thx very much.....One thing i want to say dat ur all answers are 100% Correct...I have noted it many times..Grt Effort..Salute to U!!!!!!!

hello Sir or frnd,tell me one thing more is that possible to show image in tooltip?????//

Thanks,

Mark this thread as Solved if you get solution.

Sir i get the solution..BUt i have one other probs..I want to draw image & text in tooltip..
Currently I m able to draw only text...To drwa image..I searced on the net & found the foll. link-
http://www.vb-helper.com/howto_2005_ownerdraw_tooltip.html

Private Sub ToolTip1_Draw(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawToolTipEventArgs) Handles ToolTip1.Draw
        e.DrawBackground()
        e.DrawBorder()

        ' Draw the text.
        Using sf As New StringFormat()
            sf.Alignment = StringAlignment.Near
            sf.LineAlignment = StringAlignment.Center
            Dim rect As New Rectangle(50, 0, e.Bounds.Width - _
                50, e.Bounds.Height)
            e.Graphics.DrawString(e.ToolTipText, e.Font, _
                Brushes.Green, rect, sf)
        End Using

        ' Draw the image.
        e.Graphics.DrawImage(My.Resources.btnURLGO, 9, 9)
    End Sub

    Private Sub ToolTip1_Popup(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PopupEventArgs) Handles ToolTip1.Popup
        Dim wid As Integer = e.ToolTipSize.Width + 50
        Dim hgt As Integer = e.ToolTipSize.Height
        If hgt < 50 Then hgt = 50
        e.ToolTipSize = New Size(wid, hgt)
    End Sub

But these events are not firing..Can u help me on this matter!!!!!!!!!

Set OwnerDraw Property of tooltip control and also add two events - Draw and Popup.

hello,
i am doing the room management system project in vb.net.in that i have used the list view to display the room details.so when i reserve a room,it will goes to the corner of listview from the previous place.but it want to be stay that same place.so anyone help me to solve this problem.
thanking you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.