将透明控件用作不可见触发器的最佳方式

Best way to use transparent controls as invisible triggers

一旦我开发了一个 vb6 代码来使用透明控件(不记得我是否使用按钮或 PictureBoxes),坐标作为不可见标签和不可见标签来显示集体照片中每个人的名字,就像 facebook 那样。现在,我正试图在 vb.net 重新创建相同的代码,但我无法让它工作..

如果我使用具有透明.backcolor、无文本和无边框、平面样式等的按钮来标记照片区域,当我将鼠标移到控件上时它们会变得不透明。如果我禁用鼠标悬停功能变得不可见。

如果出于相同的目的我使用空的 PictureBoxes,因为空的 PictureBoxes 在运行时也变得不可见 "mouse over" 函数...

我不知道必须使用哪个空的或不可见的控件才能完成此最终操作。有什么建议吗?

这是我在评论中谈论的示例:

Public Class Form1

    Private ReadOnly actionsByRectangle As New Dictionary(Of Rectangle, Action)

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'If the user clicks near the top, left corner, display a message.
        actionsByRectangle.Add(New Rectangle(10, 10, 100, 100),
                               Sub() MessageBox.Show("Hello World"))

        'If the user clicks near the bottom, right corner, minimise the form.
        actionsByRectangle.Add(New Rectangle(ClientSize.Width - 110,
                                             ClientSize.Height - 110,
                                             100,
                                             100),
                               Sub() WindowState = FormWindowState.Minimized)
    End Sub

    Private Sub Form1_MouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
        For Each rectangle As Rectangle In actionsByRectangle.Keys
            If rectangle.Contains(e.Location) Then
                'We have found a rectangle containing the point that was clicked so execute the corresponding action.
                actionsByRectangle(rectangle).Invoke()

                'Don't look for any more matches.
                Exit For
            End If
        Next
    End Sub

    'Uncomment the code below to see the click targets drawn on the form.
    'Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
    '    For Each rectangle As Rectangle In actionsByRectangle.Keys
    '        e.Graphics.DrawRectangle(Pens.Black, rectangle)
    '    Next
    'End Sub

End Class

请注意,我已经在其中添加了代码,如果您想查看它们,可以在表单上绘制方框,但这些只是区域的表示,而不是 Rectangle 值本身。