Search code examples
vb.netwinformstooltip

Child controls blocking FlowLayoutPanel tooltips


I'm using a FlowLayoutPanel to programmatically display a dynamic list of items using the Label control. However, the FlowLayoutPanel's tooltip will only trigger when hovering on whatever blank area remains after populating the panel.

I tried adding a control.SendToBack when adding the labels and a Control.BringToFront on the Panel.

Is there a way to make the FlowLayoutPanel's tooltip display even when hovering over a child control?


Solution

  • I'm not aware of a way to make a control's tooltip treat the child controls as part of the parent one. As a workaround, you could set the tooltip to both the parent control and its children once created. For example, you can call the following right after adding your Label controls:

    Dim tTip As New ToolTip() With {.ReshowDelay = 0}
    tTip.SetToolTip(FlowLayoutPanel1, "Hello world!")
    For Each c As Control In FlowLayoutPanel1.Controls
        tTip.SetToolTip(c, "Hello world!")
    Next
    

    If you add your Label controls dynamically (not at one time), you can set the tooltip of each control once it's added. This can easily be done using the ControlAdded event of the FlowLayoutPanel:

    ' You can add TootTip1 in design time and set its properties.
    ' Then, call the following line on Form_Load or even set it ad design time if you want.
    ToolTip1.SetToolTip(FlowLayoutPanel1, "Hello world!")
    
    Private Sub FlowLayoutPanel1_ControlAdded(sender As Object, e As ControlEventArgs) Handles FlowLayoutPanel1.ControlAdded
        ToolTip1.SetToolTip(e.Control, ToolTip1.GetToolTip(FlowLayoutPanel1))
    End Sub