Code 1Private Sub ListBox1_MouseMove()Sub ListBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseMove 2 Dim MousePositionInClientCoords As Point = Me.ListBox1.PointToClient(Me.MousePosition) 3 Dim indexUnderTheMouse As Integer = Me.ListBox1.IndexFromPoint(MousePositionInClientCoords) 4 If indexUnderTheMouse > -1 Then 5 Dim s As String = Me.ListBox1.Items(indexUnderTheMouse).ToString 6 Dim g As Graphics = Me.ListBox1.CreateGraphics 7 If g.MeasureString(s, Me.ListBox1.Font).Width > Me.ListBox1.ClientRectangle.Width Then 8 Me.ToolTip1.SetToolTip(Me.ListBox1, s) 9 Else 10 Me.ToolTip1.SetToolTip(Me.ListBox1, "") 11 End If 12 g.Dispose() 13 End If 14 End Sub 15 或者 Code 1 Private Sub ListBox1_MouseMove()Sub ListBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseMove 2 Dim MousePositionInClientCoords As Point = New Point(e.X, e.Y) 3 Dim indexUnderTheMouse As Integer = Me.ListBox1.IndexFromPoint(MousePositionInClientCoords) 4 If indexUnderTheMouse > -1 Then 5 Dim s As String = Me.ListBox1.Items(indexUnderTheMouse).ToString 6 Dim g As Graphics = Me.ListBox1.CreateGraphics 7 If g.MeasureString(s, Me.ListBox1.Font).Width > Me.ListBox1.ClientRectangle.Width Then 8 Me.ToolTip1.SetToolTip(Me.ListBox1, s) 9 Else 10 Me.ToolTip1.SetToolTip(Me.ListBox1, "") 11 End If 12 g.Dispose() 13 End If 14 End Sub