User Control in TableLayoutPanel Won't Handle Mouse Clicks

When I click on a user control located in a tablelayoutpanel, it appears that the event is never raised.

The program creates multiple workingblockUCs and displays them correctly, but when I put a breakpoint on sub blockUC_mouseclick, the breakpoint never gets hit.
class form2
 Friend WithEvents WorkingBlockUC As BlockUC

Sub drawblock(ByVal coordx As Integer, ByVal coordy As Integer, ByVal gridnum As Integer, ByVal wbc As BlockCollection)
        wbc.getblock(coordx, coordy)
WorkingBlockUC = New BlockUC
                WorkingBlockUC.setup()
        TableLayoutPanel1.Controls.Add(WorkingBlockUC, coordx, coordy)
     



Private Sub blockUC_Mouseclick(ByVal sender As Object, ByVal e As  _
       System.Windows.Forms.MouseEventArgs) Handles WorkingBlockUC.MouseClick
        Dim row As Integer = 0
        Dim verticalOffset As Integer = 0

        For Each h As Integer In TableLayoutPanel1.GetRowHeights()
            Dim column As Integer = 0
            Dim horizontalOffset As Integer = 0

            For Each w As Integer In TableLayoutPanel1.GetColumnWidths()
                Dim rectangle As New Rectangle(horizontalOffset, verticalOffset, w, h)

                'If rectangle.Contains(e.) Then
                '    CMSBlock.Show(Me, pt)
                '    clearselected()
                '    drawcollection(thisgridnum, wbc)
                '    'Trace.WriteLine([String].Format("row {0}, column {1} was clicked", row, column))
                '    Exit Sub
                'End If

                horizontalOffset += w
                column += 1
            Next

            verticalOffset += h

            row += 1

        Next
    End Sub

Open in new window

alukesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
You have:

    Friend WithEvents WorkingBlockUC As BlockUC

The "WithEvents" paradigm can only handle ONE object (whatever "WorkingBluckUC" was last assigned).

To handle multiple instances you'd have to use AddHandler() instead (and get rid of the WithEvents declaration).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alukesAuthor Commented:
Dead on.

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.