How to Pass MouseEvents Generated in Child to its Container

csharp Kenya
  • 12 years ago

    I have a Label contained in another Label

    Class MyLabel
     public MyLabel()
      Label innerLabel = new Label();

    MyLabel outerLabel = new MyLabel();
    Now If I Do outerLabel.MouseUp += MyHandler

    Now MyHandler would not be invoked because everytime I Click over outerLabel Mouse Events would be generated on the innerLabel and not on the OuterLabel. So what modifications do I need to make to innerLabel(or OuterLabel) so that the InnerLabel passes MouseEvents to its Container OuterLabel.


  • 12 years ago

    Your class should be handling the relevant events of the child control and then behaving appropriately.  For instance, your class can handle the Label's Click event and then call its OnClick method to raise its own Click event.  With Click there's no issue but just make sure that if the 'e' argument contains any data that you perform the appropriate translation.   The MouseClick event would be an example of where that would be required, with the X and Y properties initially being relative to the child control.  You'd have to create a new MouseEventArgs object and provide translated coordinates.

  • 12 years ago

    Thanks for the Reply jmcilhinney, I've got the Click Event Working Fine
    I think you've got my question correctly. I was also thinking along similar lines just could not find right methods.

    So this is how I'm doing it

    class YoLabel{

    this.textLabel = new TextLabe();

    this.textLabel.Click +=delegate(object o, EventArgs ev){





    this.textLabel.MouseUp +=delegate(object o, MouseEventArgs mev){

    mev = changeCoords(mev) 



     and then handle MouseUp on my YoLabel as

    yoLabel.MouseUp += myHandler

    BTW. YoLabel is a nice SMOOTH SCROLLING Label with Circular Edges with Transparency Adjustable Background and Gradient Painting.
    Interested then visit or to see YoLabel in action


Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perl - The only language that looks the same before and after RSA encryption.” - Keith Bostic