Search code examples
vb.netbuttoncontrolspictureboxinvisible

Best way to use transparent controls as invisible triggers


Once I developed a vb6 code to use transparent controls (Don't remember if I used Buttons or PictrureBoxes) with coordinates as invisible tags & invisible labels to show the names of eachone at groupal photos like Facebook does. Now I'm trying to recreate the same code at vb.net but I can't reach to get it work..

If I use Buttons with transparent .backcolor, no-text and no-borders, flat style, etc. to mark the photo area, they become opaque when I move the mouse over the control. if I disable becomes invisible for the mouse-over function.

If I use empty PictureBoxes instead for the same purpose, as are empty they became invisible at runtime also for the "mouse over" function...

I don't know which empty or invisible control must use to this finality. any suggestion?


Solution

  • Here is an example of what I was talking about in my comments:

    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
    

    Note that I have added code there that can draw the boxes on the form if you want to see them, but those are just representations of the areas, not the Rectangle values themselves.