Question

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?

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top