0

I have a custom control DigitalPanel that has a FlowLayoutPanel(viewPanel), which is filled with custom controls (DigitalIndicator). When a user clicks on a DigitalIndicator within the viewPanel I would like to notify DigitalPanel of this event. Currently I watch for viewPanel's onMouseClick event, but this is only triggered when the spaces between the DigitialIndicators is clicked and not when they are click on themselves.

So from what I have gathered on Stack Overflow is that I need to get the onMouseClick event from each DigitalIndicator before I add it to the viewPanel and watch for these events from/in the viewPanel's onMouseClick event.

So then if a DigitalIndicator is clicked, it will raise the event, viewPanel will see that and in turn raise its onMouseClick event which the DigitalPanel will see and handle?

My issues is I am not sure how to get the DigitalIndicator's onMouseClick event from it. Here is what I have.

// This is from the DigitalPanel class when a new DigitalIndicator is being added

DigitalIndicatior newDigInd= new DigitalIndicatior();
this.viewPanel.MouseClick += new System.Windows.Forms.MouseEventHandler(newDigInd.);

I am not sure what the arguments to the MouseEventHandler should be exactly. Suggestions?

AnotherUser
  • 1,311
  • 1
  • 14
  • 35

1 Answers1

0

If you can define event in the viewPanel, then you can do the following

  • Declare an Event in viewPanel (DigitalIndicatorClicked)
  • When DigitalIndicator is clicked, its Click event will raise viewPanel's event DigitalIndicatorClicked, passing the sender (DigitalIndicator) as sender to this raised event
  • Your DigitalPanel will handle the DigitalIndicatorClicked event of the ViewPanel. This event handler will also receive the original DigitalIndicator object as sender (passed in above step)
Manish Dalal
  • 1,768
  • 1
  • 10
  • 14
  • Something like the first answer to this question? http://stackoverflow.com/questions/6644247/simple-custom-event – AnotherUser May 08 '14 at 17:35
  • Yup (y). The only this is that this answer shows you how to declare and raise event (defined in viewPanel) from DigitalIndicator object. You have to add another level to it where viewPanel can raise event declared in DigitalPanel – Manish Dalal May 08 '14 at 17:42
  • Is there an easier way then declaring my own events. I cannot do it with the predefined OnMouseClick event(s)? – AnotherUser May 08 '14 at 17:45
  • You can raise the `OnMouseClick` event of viewPanel from the `DigitalIndicator_OnMouseClick` event handler by writing the line `OnMouseClick(sender, e)` and handle that event in DigitalPanel (`viewPanel_OnMouseClick` event handler) – Manish Dalal May 08 '14 at 17:47