阻止 FlowLayoutPanel 工具提示的子控件

Child controls blocking FlowLayoutPanel tooltips

我正在使用 FlowLayoutPanel 通过 Label 控件以编程方式显示项目的动态列表。但是,FlowLayoutPanel 的工具提示只会在填充面板后悬停在任何空白区域时触发。

我尝试在添加标签时添加 control.SendToBack,在面板上添加 Control.BringToFront

有没有办法让 FlowLayoutPanel 的工具提示在悬停在子控件上时也能显示?

我不知道有什么方法可以使控件的工具提示将子控件视为父控件的一部分。作为解决方法,您可以将工具提示设置为父控件及其子控件一旦创建。例如,您可以在添加 Label 控件后立即调用以下命令:

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

如果您动态添加 Label 控件(不是一次添加),您可以在添加每个控件后设置工具提示。这可以使用 FlowLayoutPanel:

ControlAdded 事件轻松完成
' 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