0

我有一个具有某些尺寸的列表框,其中
一些项目比 ListBox 控件的宽度还要大。
当我将鼠标移到这些项目上时,我想查看所有名称。我正在使用 vb.net

4

1 回答 1

1

尝试这个:

Private Sub ListBox1_MouseMove (ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseMove
    Dim ListMousePosition As Point = Me.ListBox1.PointToClient(Me.MousePosition)
    Dim itemIndex As Integer = Me.ListBox1.IndexFromPoint(ListMousePosition)
    If itemIndex > -1 Then
        Dim s As String = Me.ListBox1.Items(itemIndex).ToString()
        Dim g As Graphics = Me.ListBox1.CreateGraphics()
        If g.MeasureString(s, Me.ListBox1.Font).Width > Me.ListBox1.ClientRectangle.Width Then
        Me.ToolTip.SetToolTip(Me.ListBox1, s)
        else
        Me.ToolTip.SetToolTip(Me.ListBox, "")
        End If
        g.Dispose()
    End If
End Sub
于 2013-11-13T19:58:55.563 回答