Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27362

[RESOLVED] ComboBox Item Tool Tips. 90% Working. Drawing Bug.[UPDATED THE OP WITH SCREENSHOT]

$
0
0
So i've got this Combobox with tooltips for each individual item and it 90% works apart from this visual drawing bug.

Firstly, I got the code from stackoverflow and just converted it to vb.net. Heres the link:
http://stackoverflow.com/questions/6...in-a-combo-box

The problem is that when you first drop down the ComboBox the the tooltip for the last item is being shown. I think this is because the items and the tooltips are drawn together. So when the last item is drawn the tooltip is drawn too.

Here is my code:

Code:

Private Sub drawToolTips(sender As Object, e As DrawItemEventArgs) Handles CB_TypeofOrder.DrawItem

        'Dim brush = New SolidBrush(e.ForeColor)
        If (e.Index < 0) Then Return
        Select Case e.Index
            Case Is = 0
                tip = "This is for orders what are placed through the web." & vbNewLine & "This will not send an email to the supplier contact email as the products are ordered through an online order form."
            Case Is = 1
                tip = "This is for orders where the order cost cannot be calculated yet. E.G: A mechanic coming in to give you a quote on a repair." & vbNewLine & "When the cost has been calculated the order will need to be updated."
            Case Is = 2
                tip = "This is for orders which do not fit into the specification of the two above. Most orders will be this." & vbNewLine & "This type of order flows classically, you add the header and line items and once approved, you send to supplier. "
            Case Is = 3
                tip = ""
            Case Else
                tip = "error"
        End Select
        e.DrawBackground()
        ' Using (brush)
        'draws the combo items
        e.Graphics.DrawString(CB_TypeofOrder.GetItemText(CB_TypeofOrder.Items(e.Index)), e.Font, Brushes.Black, e.Bounds)
        'End Using
        If (e.State And DrawItemState.Selected = DrawItemState.Selected) Then
            'If (e.State And DrawItemState.HotLight = DrawItemState.HotLight) Then
            TT_PO.Show(tip, CB_TypeofOrder, e.Bounds.Right, e.Bounds.Bottom)
        End If
        e.DrawFocusRectangle()
    End Sub

I also use use the dropdownclosed event to hide the tooltips:
Code:

Private Sub dropDownClosed(sender As Object, e As EventArgs) Handles CB_TypeofOrder.DropDownClosed
        TT_PO.Hide(CB_TypeofOrder)
    End Sub

Its also worth nothing that the draw mode of the combobox is owerdrawfixed.

So the problem is that when the combo box is initially dropped a tooltip for the last item is drawn even though none of the items are being hovered over.
EXAMPLE:
http://prntscr.com/8bj5sd

Any help appreciated.

Viewing all articles
Browse latest Browse all 27362

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>