Question

I have a List Box which have certain dimentions
Some of the Items are loger than the width of the ListBox control.
When I pass the mouse over these Items I want to see all the name. I'm using vb.net

Was it helpful?

Solution

Try this:

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top