Link to home
Start Free TrialLog in
Avatar of alukes
alukes

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alukes
alukes

ASKER

Dead on.

Thanks