how to add tooltips on winform list box items

2019-07-02 21:54发布

I am using win form's list box control.

I want to add tool tips on list items. I could not find any default such properties.

Please share me , how can i add tool tips on winform list box items ?

Thank You

4条回答
地球回转人心会变
2楼-- · 2019-07-02 22:24

I thought I'd mention that there is a ShowItemToolTips boolean attribute on ListView, if you want to use that instead of a ListBox. Set that attribute to true and then assign the ToolTipText values on the ListView items.

查看更多
家丑人穷心不美
3楼-- · 2019-07-02 22:47

If you want to do it in a listbox you will need to do it manually. Add a tooltip to the form and update the tooltip based on the mouses postion. An easier way to do this might be to use a DataGridView control like this:

    DataGridView1.RowHeadersVisible = False
    DataGridView1.ColumnHeadersVisible = False
    DataGridView1.Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader
    Dim mydata As String() = {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"}
    For Each dataitem As String In mydata
        DataGridView1.Rows.Add(dataitem)
    Next
    For Each row As DataGridViewRow In DataGridView1.Rows
        row.Cells(0).ToolTipText = "ToolTip for " & row.Cells(0).Value
    Next row
查看更多
太酷不给撩
4楼-- · 2019-07-02 22:47

I able to resolve thorough below ways:

'tooltip
Dim toolTip As ToolTip = New ToolTip()
    Private Sub lstReports_MouseMove(sender As Object, e As MouseEventArgs) Handles lstReports.MouseMove
    Dim index As Integer = lstReports.IndexFromPoint(e.Location)
    If (index <> -1 AndAlso index < lstReports.Items.Count) Then
        If (toolTip.GetToolTip(lstReports) <> lstReports.Items(index).ToString()) Then
            toolTip.SetToolTip(lstReports, lstReports.Items(index).ToString())
        End If
    End If
End Sub

one ref link:

http://dotnetfollower.com/wordpress/2012/01/winforms-show-individual-tooltip-for-each-listbox-item/ Thanks

查看更多
小情绪 Triste *
5楼-- · 2019-07-02 22:48

Sadly, there is no implemented way to show ToolTips on each individual ListBox Item.

You can create your own ListBox control that allows you to do that, like this one: http://www.codeproject.com/Articles/457444/Listbox-Control-with-Tooltip-for-Each-Item

查看更多
登录 后发表回答