vb.net 如何在 winform 列表框项目上添加工具提示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23055206/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 17:21:56  来源:igfitidea点击:

how to add tooltips on winform list box items

.netvb.netwinformslistboxtooltip

提问by dsi

I am using win form's list box control.

我正在使用 win 表单的列表框控件。

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 ?

请分享我,如何在 winform 列表框项目上添加工具提示?

Thank You

谢谢你

回答by adrianwadey

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:

如果您想在列表框中执行此操作,则需要手动执行此操作。向表单添加工具提示并根据鼠标位置更新工具提示。一种更简单的方法可能是使用像这样的 DataGridView 控件:

    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

回答by BaffledBill

I thought I'd mention that there is a ShowItemToolTipsboolean attribute on ListView, if you want to use that instead of a ListBox. Set that attribute to trueand then assign the ToolTipTextvalues on the ListViewitems.

我想我会提到 上有一个ShowItemToolTips布尔属性ListView,如果你想使用它而不是ListBox. 将该属性设置为true,然后ToolTipTextListView项目上分配值。

回答by dsi

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

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

回答by SysDragon

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

遗憾的是,没有实现在每个单独的 ListBox 项上显示工具提示的方法。

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

您可以创建自己的 ListBox 控件,允许您执行此操作,例如:http: //www.codeproject.com/Articles/457444/Listbox-Control-with-Tooltip-for-Each-Item