0

I am trying to pass the mouse up events of controls onto its parent control. I have my control, a panel in it, then 3 controls on the panel. This is a custom control added to a flow layout panel at runtime.

I am able to access the panel through the main code by using add handler, but everytime I click one of the controls on that panel I would like to pass the mouse up event through so that the panels events will fire.

Public Class Repeater

Public Event RepeaterMouseUp As MouseEventHandler

Private Sub on_Mouse_Up(ByVal sender As Object, ByVal e As MouseEventArgs) 'Handles TextBox1.onclick
    RaiseEvent RepeaterMouseUp(sender, e)
End Sub

Private Sub Repeater_Load(sender As Object, e As EventArgs) Handles Me.Load
    AddHandler lblRecName.MouseUp, AddressOf on_Mouse_Up
    AddHandler lblNote.MouseUp, AddressOf on_Mouse_Up
    AddHandler strRating.MouseUp, AddressOf on_Mouse_Up
End Sub

Private Sub lblNote_MouseUp(sender As Object, e As MouseEventArgs) Handles lblNote.MouseUp
    RaiseEvent RepeaterMouseUp(sender, e)
End Sub

Private Sub Panel1_MouseUp(sender As Object, e As MouseEventArgs) Handles Panel1.MouseUp
    RaiseEvent RepeaterMouseUp(sender, e)
End Sub

End Class

I cannot seem to find any usable examples of passing mouse events through to the parent control. I appreciate any help.

Recoil
  • 65
  • 7
  • your custom control looks more like a UserControl. Typically a UC will handle most of the child control events up to a point when a custom event is raised for the the form to consume. If you need the form to know about control events you need to bubble them up - in those events, have the UC raise an event the form can subscribe to. – Ňɏssa Pøngjǣrdenlarp Aug 04 '15 at 18:22
  • Agreed. If you have no need for the click events in the controls, however, then you can [make them transparent to clicks](http://stackoverflow.com/questions/31353202/how-to-fix-borderless-form-resize-with-controls-on-borders-of-the-form) using the approach outlined by Hans Passant. – Idle_Mind Aug 04 '15 at 18:30
  • Edit added. Plutonix you were right, it is a UserControl. I keep forgetting the differences. Both comments were helpful though for me to find the answer. I didn't actually need to control click events to do anything except pass the click to the parent, which is working now. Thanks for the assistance! – Recoil Aug 04 '15 at 18:57
  • Please post your solution as an answer instead of a question update so that others may benefit from the Q/A format. – Sam Axe Aug 04 '15 at 19:37

1 Answers1

0

With the help in the comments I figured out a way to do this. A created add handlers for all of the child controls on my main form, didn't even touch the UserControl:

AddHandler rptr.lblRecName.MouseUp, AddressOf Child_MouseUp
AddHandler rptr.lblNote.MouseUp, AddressOf Child_MouseUp
AddHandler rptr.strRating.MouseUp, AddressOf Child_MouseUp

When my panel is clicked on my main form, in another sub I am setting the parent control, which is the Repeater UserControl, backcolor to black to look like a selection, and populating a datagrid with stuff based off the controls lblRecName.Text.

Private Sub Child_MouseUp(ByVal sender As System.Object, ByVal e As MouseEventArgs)

    Dim ctl As Control = sender

    flpControl_Click(ctl.Parent, e)

End Sub

TBH, this seems like a hacky way to go about handling this issue, but it works. Thanks guys!

Recoil
  • 65
  • 7